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 TestHalfSqrt extends RSBaseCompute { 29 30 private ScriptC_TestHalfSqrt script; 31 private ScriptC_TestHalfSqrtRelaxed scriptRelaxed; 32 33 @Override setUp()34 protected void setUp() throws Exception { 35 super.setUp(); 36 script = new ScriptC_TestHalfSqrt(mRS); 37 scriptRelaxed = new ScriptC_TestHalfSqrtRelaxed(mRS); 38 } 39 40 public class ArgumentsFloatFloat { 41 public float inV; 42 public Target.Floaty out; 43 } 44 checkHalfSqrtFloatFloat()45 private void checkHalfSqrtFloatFloat() { 46 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xa15db5fal, false); 47 try { 48 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 49 script.forEach_testHalfSqrtFloatFloat(inV, out); 50 verifyResultsHalfSqrtFloatFloat(inV, out, false); 51 } catch (Exception e) { 52 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testHalfSqrtFloatFloat: " + e.toString()); 53 } 54 try { 55 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 56 scriptRelaxed.forEach_testHalfSqrtFloatFloat(inV, out); 57 verifyResultsHalfSqrtFloatFloat(inV, out, true); 58 } catch (Exception e) { 59 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testHalfSqrtFloatFloat: " + e.toString()); 60 } 61 } 62 verifyResultsHalfSqrtFloatFloat(Allocation inV, Allocation out, boolean relaxed)63 private void verifyResultsHalfSqrtFloatFloat(Allocation inV, Allocation out, boolean relaxed) { 64 float[] arrayInV = new float[INPUTSIZE * 1]; 65 Arrays.fill(arrayInV, (float) 42); 66 inV.copyTo(arrayInV); 67 float[] arrayOut = new float[INPUTSIZE * 1]; 68 Arrays.fill(arrayOut, (float) 42); 69 out.copyTo(arrayOut); 70 StringBuilder message = new StringBuilder(); 71 boolean errorFound = false; 72 for (int i = 0; i < INPUTSIZE; i++) { 73 for (int j = 0; j < 1 ; j++) { 74 // Extract the inputs. 75 ArgumentsFloatFloat args = new ArgumentsFloatFloat(); 76 args.inV = arrayInV[i]; 77 // Figure out what the outputs should have been. 78 Target target = new Target(Target.FunctionType.HALF, Target.ReturnType.FLOAT, relaxed); 79 CoreMathVerifier.computeHalfSqrt(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 if (!errorFound) { 87 errorFound = true; 88 message.append("Input inV: "); 89 appendVariableToMessage(message, args.inV); 90 message.append("\n"); 91 message.append("Expected output out: "); 92 appendVariableToMessage(message, args.out); 93 message.append("\n"); 94 message.append("Actual output out: "); 95 appendVariableToMessage(message, arrayOut[i * 1 + j]); 96 if (!args.out.couldBe(arrayOut[i * 1 + j])) { 97 message.append(" FAIL"); 98 } 99 message.append("\n"); 100 message.append("Errors at"); 101 } 102 message.append(" ["); 103 message.append(Integer.toString(i)); 104 message.append(", "); 105 message.append(Integer.toString(j)); 106 message.append("]"); 107 } 108 } 109 } 110 assertFalse("Incorrect output for checkHalfSqrtFloatFloat" + 111 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 112 } 113 checkHalfSqrtFloat2Float2()114 private void checkHalfSqrtFloat2Float2() { 115 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x42519b8el, false); 116 try { 117 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 118 script.forEach_testHalfSqrtFloat2Float2(inV, out); 119 verifyResultsHalfSqrtFloat2Float2(inV, out, false); 120 } catch (Exception e) { 121 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testHalfSqrtFloat2Float2: " + e.toString()); 122 } 123 try { 124 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 125 scriptRelaxed.forEach_testHalfSqrtFloat2Float2(inV, out); 126 verifyResultsHalfSqrtFloat2Float2(inV, out, true); 127 } catch (Exception e) { 128 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testHalfSqrtFloat2Float2: " + e.toString()); 129 } 130 } 131 verifyResultsHalfSqrtFloat2Float2(Allocation inV, Allocation out, boolean relaxed)132 private void verifyResultsHalfSqrtFloat2Float2(Allocation inV, Allocation out, boolean relaxed) { 133 float[] arrayInV = new float[INPUTSIZE * 2]; 134 Arrays.fill(arrayInV, (float) 42); 135 inV.copyTo(arrayInV); 136 float[] arrayOut = new float[INPUTSIZE * 2]; 137 Arrays.fill(arrayOut, (float) 42); 138 out.copyTo(arrayOut); 139 StringBuilder message = new StringBuilder(); 140 boolean errorFound = false; 141 for (int i = 0; i < INPUTSIZE; i++) { 142 for (int j = 0; j < 2 ; j++) { 143 // Extract the inputs. 144 ArgumentsFloatFloat args = new ArgumentsFloatFloat(); 145 args.inV = arrayInV[i * 2 + j]; 146 // Figure out what the outputs should have been. 147 Target target = new Target(Target.FunctionType.HALF, Target.ReturnType.FLOAT, relaxed); 148 CoreMathVerifier.computeHalfSqrt(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 if (!errorFound) { 156 errorFound = true; 157 message.append("Input inV: "); 158 appendVariableToMessage(message, args.inV); 159 message.append("\n"); 160 message.append("Expected output out: "); 161 appendVariableToMessage(message, args.out); 162 message.append("\n"); 163 message.append("Actual output out: "); 164 appendVariableToMessage(message, arrayOut[i * 2 + j]); 165 if (!args.out.couldBe(arrayOut[i * 2 + j])) { 166 message.append(" FAIL"); 167 } 168 message.append("\n"); 169 message.append("Errors at"); 170 } 171 message.append(" ["); 172 message.append(Integer.toString(i)); 173 message.append(", "); 174 message.append(Integer.toString(j)); 175 message.append("]"); 176 } 177 } 178 } 179 assertFalse("Incorrect output for checkHalfSqrtFloat2Float2" + 180 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 181 } 182 checkHalfSqrtFloat3Float3()183 private void checkHalfSqrtFloat3Float3() { 184 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x386cbc6cl, false); 185 try { 186 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 187 script.forEach_testHalfSqrtFloat3Float3(inV, out); 188 verifyResultsHalfSqrtFloat3Float3(inV, out, false); 189 } catch (Exception e) { 190 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testHalfSqrtFloat3Float3: " + e.toString()); 191 } 192 try { 193 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 194 scriptRelaxed.forEach_testHalfSqrtFloat3Float3(inV, out); 195 verifyResultsHalfSqrtFloat3Float3(inV, out, true); 196 } catch (Exception e) { 197 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testHalfSqrtFloat3Float3: " + e.toString()); 198 } 199 } 200 verifyResultsHalfSqrtFloat3Float3(Allocation inV, Allocation out, boolean relaxed)201 private void verifyResultsHalfSqrtFloat3Float3(Allocation inV, Allocation out, boolean relaxed) { 202 float[] arrayInV = new float[INPUTSIZE * 4]; 203 Arrays.fill(arrayInV, (float) 42); 204 inV.copyTo(arrayInV); 205 float[] arrayOut = new float[INPUTSIZE * 4]; 206 Arrays.fill(arrayOut, (float) 42); 207 out.copyTo(arrayOut); 208 StringBuilder message = new StringBuilder(); 209 boolean errorFound = false; 210 for (int i = 0; i < INPUTSIZE; i++) { 211 for (int j = 0; j < 3 ; j++) { 212 // Extract the inputs. 213 ArgumentsFloatFloat args = new ArgumentsFloatFloat(); 214 args.inV = arrayInV[i * 4 + j]; 215 // Figure out what the outputs should have been. 216 Target target = new Target(Target.FunctionType.HALF, Target.ReturnType.FLOAT, relaxed); 217 CoreMathVerifier.computeHalfSqrt(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 if (!errorFound) { 225 errorFound = true; 226 message.append("Input inV: "); 227 appendVariableToMessage(message, args.inV); 228 message.append("\n"); 229 message.append("Expected output out: "); 230 appendVariableToMessage(message, args.out); 231 message.append("\n"); 232 message.append("Actual output out: "); 233 appendVariableToMessage(message, arrayOut[i * 4 + j]); 234 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 235 message.append(" FAIL"); 236 } 237 message.append("\n"); 238 message.append("Errors at"); 239 } 240 message.append(" ["); 241 message.append(Integer.toString(i)); 242 message.append(", "); 243 message.append(Integer.toString(j)); 244 message.append("]"); 245 } 246 } 247 } 248 assertFalse("Incorrect output for checkHalfSqrtFloat3Float3" + 249 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 250 } 251 checkHalfSqrtFloat4Float4()252 private void checkHalfSqrtFloat4Float4() { 253 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x2e87dd4al, false); 254 try { 255 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 256 script.forEach_testHalfSqrtFloat4Float4(inV, out); 257 verifyResultsHalfSqrtFloat4Float4(inV, out, false); 258 } catch (Exception e) { 259 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testHalfSqrtFloat4Float4: " + e.toString()); 260 } 261 try { 262 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 263 scriptRelaxed.forEach_testHalfSqrtFloat4Float4(inV, out); 264 verifyResultsHalfSqrtFloat4Float4(inV, out, true); 265 } catch (Exception e) { 266 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testHalfSqrtFloat4Float4: " + e.toString()); 267 } 268 } 269 verifyResultsHalfSqrtFloat4Float4(Allocation inV, Allocation out, boolean relaxed)270 private void verifyResultsHalfSqrtFloat4Float4(Allocation inV, Allocation out, boolean relaxed) { 271 float[] arrayInV = new float[INPUTSIZE * 4]; 272 Arrays.fill(arrayInV, (float) 42); 273 inV.copyTo(arrayInV); 274 float[] arrayOut = new float[INPUTSIZE * 4]; 275 Arrays.fill(arrayOut, (float) 42); 276 out.copyTo(arrayOut); 277 StringBuilder message = new StringBuilder(); 278 boolean errorFound = false; 279 for (int i = 0; i < INPUTSIZE; i++) { 280 for (int j = 0; j < 4 ; j++) { 281 // Extract the inputs. 282 ArgumentsFloatFloat args = new ArgumentsFloatFloat(); 283 args.inV = arrayInV[i * 4 + j]; 284 // Figure out what the outputs should have been. 285 Target target = new Target(Target.FunctionType.HALF, Target.ReturnType.FLOAT, relaxed); 286 CoreMathVerifier.computeHalfSqrt(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 if (!errorFound) { 294 errorFound = true; 295 message.append("Input inV: "); 296 appendVariableToMessage(message, args.inV); 297 message.append("\n"); 298 message.append("Expected output out: "); 299 appendVariableToMessage(message, args.out); 300 message.append("\n"); 301 message.append("Actual output out: "); 302 appendVariableToMessage(message, arrayOut[i * 4 + j]); 303 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 304 message.append(" FAIL"); 305 } 306 message.append("\n"); 307 message.append("Errors at"); 308 } 309 message.append(" ["); 310 message.append(Integer.toString(i)); 311 message.append(", "); 312 message.append(Integer.toString(j)); 313 message.append("]"); 314 } 315 } 316 } 317 assertFalse("Incorrect output for checkHalfSqrtFloat4Float4" + 318 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 319 } 320 testHalfSqrt()321 public void testHalfSqrt() { 322 checkHalfSqrtFloatFloat(); 323 checkHalfSqrtFloat2Float2(); 324 checkHalfSqrtFloat3Float3(); 325 checkHalfSqrtFloat4Float4(); 326 } 327 } 328