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 TestFastDistance extends RSBaseCompute { 29 30 private ScriptC_TestFastDistance script; 31 private ScriptC_TestFastDistanceRelaxed scriptRelaxed; 32 33 @Override setUp()34 protected void setUp() throws Exception { 35 super.setUp(); 36 script = new ScriptC_TestFastDistance(mRS); 37 scriptRelaxed = new ScriptC_TestFastDistanceRelaxed(mRS); 38 } 39 40 public class ArgumentsFloatFloatFloat { 41 public float inLeftVector; 42 public float inRightVector; 43 public Target.Floaty out; 44 } 45 checkFastDistanceFloatFloatFloat()46 private void checkFastDistanceFloatFloatFloat() { 47 Allocation inLeftVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xb9b28b1al, false); 48 Allocation inRightVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x9f1626e3l, false); 49 try { 50 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 51 script.set_gAllocInRightVector(inRightVector); 52 script.forEach_testFastDistanceFloatFloatFloat(inLeftVector, out); 53 verifyResultsFastDistanceFloatFloatFloat(inLeftVector, inRightVector, out, false); 54 } catch (Exception e) { 55 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFastDistanceFloatFloatFloat: " + e.toString()); 56 } 57 try { 58 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 59 scriptRelaxed.set_gAllocInRightVector(inRightVector); 60 scriptRelaxed.forEach_testFastDistanceFloatFloatFloat(inLeftVector, out); 61 verifyResultsFastDistanceFloatFloatFloat(inLeftVector, inRightVector, out, true); 62 } catch (Exception e) { 63 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFastDistanceFloatFloatFloat: " + e.toString()); 64 } 65 } 66 verifyResultsFastDistanceFloatFloatFloat(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed)67 private void verifyResultsFastDistanceFloatFloatFloat(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed) { 68 float[] arrayInLeftVector = new float[INPUTSIZE * 1]; 69 Arrays.fill(arrayInLeftVector, (float) 42); 70 inLeftVector.copyTo(arrayInLeftVector); 71 float[] arrayInRightVector = new float[INPUTSIZE * 1]; 72 Arrays.fill(arrayInRightVector, (float) 42); 73 inRightVector.copyTo(arrayInRightVector); 74 float[] arrayOut = new float[INPUTSIZE * 1]; 75 Arrays.fill(arrayOut, (float) 42); 76 out.copyTo(arrayOut); 77 StringBuilder message = new StringBuilder(); 78 boolean errorFound = false; 79 for (int i = 0; i < INPUTSIZE; i++) { 80 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 81 // Create the appropriate sized arrays in args 82 // Fill args with the input values 83 args.inLeftVector = arrayInLeftVector[i]; 84 args.inRightVector = arrayInRightVector[i]; 85 Target target = new Target(Target.FunctionType.FAST, Target.ReturnType.FLOAT, relaxed); 86 CoreMathVerifier.computeFastDistance(args, target); 87 88 // Compare the expected outputs to the actual values returned by RS. 89 boolean valid = true; 90 if (!args.out.couldBe(arrayOut[i])) { 91 valid = false; 92 } 93 if (!valid) { 94 if (!errorFound) { 95 errorFound = true; 96 message.append("Input inLeftVector: "); 97 appendVariableToMessage(message, arrayInLeftVector[i]); 98 message.append("\n"); 99 message.append("Input inRightVector: "); 100 appendVariableToMessage(message, arrayInRightVector[i]); 101 message.append("\n"); 102 message.append("Expected output out: "); 103 appendVariableToMessage(message, args.out); 104 message.append("\n"); 105 message.append("Actual output out: "); 106 appendVariableToMessage(message, arrayOut[i]); 107 if (!args.out.couldBe(arrayOut[i])) { 108 message.append(" FAIL"); 109 } 110 message.append("\n"); 111 message.append("Errors at"); 112 } 113 message.append(" ["); 114 message.append(Integer.toString(i)); 115 message.append("]"); 116 } 117 } 118 assertFalse("Incorrect output for checkFastDistanceFloatFloatFloat" + 119 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 120 } 121 122 public class ArgumentsFloatNFloatNFloat { 123 public float[] inLeftVector; 124 public float[] inRightVector; 125 public Target.Floaty out; 126 } 127 checkFastDistanceFloat2Float2Float()128 private void checkFastDistanceFloat2Float2Float() { 129 Allocation inLeftVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xc7fabd9el, false); 130 Allocation inRightVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x536a30fl, false); 131 try { 132 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 133 script.set_gAllocInRightVector(inRightVector); 134 script.forEach_testFastDistanceFloat2Float2Float(inLeftVector, out); 135 verifyResultsFastDistanceFloat2Float2Float(inLeftVector, inRightVector, out, false); 136 } catch (Exception e) { 137 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFastDistanceFloat2Float2Float: " + e.toString()); 138 } 139 try { 140 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 141 scriptRelaxed.set_gAllocInRightVector(inRightVector); 142 scriptRelaxed.forEach_testFastDistanceFloat2Float2Float(inLeftVector, out); 143 verifyResultsFastDistanceFloat2Float2Float(inLeftVector, inRightVector, out, true); 144 } catch (Exception e) { 145 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFastDistanceFloat2Float2Float: " + e.toString()); 146 } 147 } 148 verifyResultsFastDistanceFloat2Float2Float(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed)149 private void verifyResultsFastDistanceFloat2Float2Float(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed) { 150 float[] arrayInLeftVector = new float[INPUTSIZE * 2]; 151 Arrays.fill(arrayInLeftVector, (float) 42); 152 inLeftVector.copyTo(arrayInLeftVector); 153 float[] arrayInRightVector = new float[INPUTSIZE * 2]; 154 Arrays.fill(arrayInRightVector, (float) 42); 155 inRightVector.copyTo(arrayInRightVector); 156 float[] arrayOut = new float[INPUTSIZE * 1]; 157 Arrays.fill(arrayOut, (float) 42); 158 out.copyTo(arrayOut); 159 StringBuilder message = new StringBuilder(); 160 boolean errorFound = false; 161 for (int i = 0; i < INPUTSIZE; i++) { 162 ArgumentsFloatNFloatNFloat args = new ArgumentsFloatNFloatNFloat(); 163 // Create the appropriate sized arrays in args 164 args.inLeftVector = new float[2]; 165 args.inRightVector = new float[2]; 166 // Fill args with the input values 167 for (int j = 0; j < 2 ; j++) { 168 args.inLeftVector[j] = arrayInLeftVector[i * 2 + j]; 169 } 170 for (int j = 0; j < 2 ; j++) { 171 args.inRightVector[j] = arrayInRightVector[i * 2 + j]; 172 } 173 Target target = new Target(Target.FunctionType.FAST, Target.ReturnType.FLOAT, relaxed); 174 CoreMathVerifier.computeFastDistance(args, target); 175 176 // Compare the expected outputs to the actual values returned by RS. 177 boolean valid = true; 178 if (!args.out.couldBe(arrayOut[i])) { 179 valid = false; 180 } 181 if (!valid) { 182 if (!errorFound) { 183 errorFound = true; 184 for (int j = 0; j < 2 ; j++) { 185 message.append("Input inLeftVector: "); 186 appendVariableToMessage(message, arrayInLeftVector[i * 2 + j]); 187 message.append("\n"); 188 } 189 for (int j = 0; j < 2 ; j++) { 190 message.append("Input inRightVector: "); 191 appendVariableToMessage(message, arrayInRightVector[i * 2 + j]); 192 message.append("\n"); 193 } 194 message.append("Expected output out: "); 195 appendVariableToMessage(message, args.out); 196 message.append("\n"); 197 message.append("Actual output out: "); 198 appendVariableToMessage(message, arrayOut[i]); 199 if (!args.out.couldBe(arrayOut[i])) { 200 message.append(" FAIL"); 201 } 202 message.append("\n"); 203 message.append("Errors at"); 204 } 205 message.append(" ["); 206 message.append(Integer.toString(i)); 207 message.append("]"); 208 } 209 } 210 assertFalse("Incorrect output for checkFastDistanceFloat2Float2Float" + 211 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 212 } 213 checkFastDistanceFloat3Float3Float()214 private void checkFastDistanceFloat3Float3Float() { 215 Allocation inLeftVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xe99971ecl, false); 216 Allocation inRightVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xaadeec29l, false); 217 try { 218 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 219 script.set_gAllocInRightVector(inRightVector); 220 script.forEach_testFastDistanceFloat3Float3Float(inLeftVector, out); 221 verifyResultsFastDistanceFloat3Float3Float(inLeftVector, inRightVector, out, false); 222 } catch (Exception e) { 223 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFastDistanceFloat3Float3Float: " + e.toString()); 224 } 225 try { 226 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 227 scriptRelaxed.set_gAllocInRightVector(inRightVector); 228 scriptRelaxed.forEach_testFastDistanceFloat3Float3Float(inLeftVector, out); 229 verifyResultsFastDistanceFloat3Float3Float(inLeftVector, inRightVector, out, true); 230 } catch (Exception e) { 231 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFastDistanceFloat3Float3Float: " + e.toString()); 232 } 233 } 234 verifyResultsFastDistanceFloat3Float3Float(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed)235 private void verifyResultsFastDistanceFloat3Float3Float(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed) { 236 float[] arrayInLeftVector = new float[INPUTSIZE * 4]; 237 Arrays.fill(arrayInLeftVector, (float) 42); 238 inLeftVector.copyTo(arrayInLeftVector); 239 float[] arrayInRightVector = new float[INPUTSIZE * 4]; 240 Arrays.fill(arrayInRightVector, (float) 42); 241 inRightVector.copyTo(arrayInRightVector); 242 float[] arrayOut = new float[INPUTSIZE * 1]; 243 Arrays.fill(arrayOut, (float) 42); 244 out.copyTo(arrayOut); 245 StringBuilder message = new StringBuilder(); 246 boolean errorFound = false; 247 for (int i = 0; i < INPUTSIZE; i++) { 248 ArgumentsFloatNFloatNFloat args = new ArgumentsFloatNFloatNFloat(); 249 // Create the appropriate sized arrays in args 250 args.inLeftVector = new float[3]; 251 args.inRightVector = new float[3]; 252 // Fill args with the input values 253 for (int j = 0; j < 3 ; j++) { 254 args.inLeftVector[j] = arrayInLeftVector[i * 4 + j]; 255 } 256 for (int j = 0; j < 3 ; j++) { 257 args.inRightVector[j] = arrayInRightVector[i * 4 + j]; 258 } 259 Target target = new Target(Target.FunctionType.FAST, Target.ReturnType.FLOAT, relaxed); 260 CoreMathVerifier.computeFastDistance(args, target); 261 262 // Compare the expected outputs to the actual values returned by RS. 263 boolean valid = true; 264 if (!args.out.couldBe(arrayOut[i])) { 265 valid = false; 266 } 267 if (!valid) { 268 if (!errorFound) { 269 errorFound = true; 270 for (int j = 0; j < 3 ; j++) { 271 message.append("Input inLeftVector: "); 272 appendVariableToMessage(message, arrayInLeftVector[i * 4 + j]); 273 message.append("\n"); 274 } 275 for (int j = 0; j < 3 ; j++) { 276 message.append("Input inRightVector: "); 277 appendVariableToMessage(message, arrayInRightVector[i * 4 + j]); 278 message.append("\n"); 279 } 280 message.append("Expected output out: "); 281 appendVariableToMessage(message, args.out); 282 message.append("\n"); 283 message.append("Actual output out: "); 284 appendVariableToMessage(message, arrayOut[i]); 285 if (!args.out.couldBe(arrayOut[i])) { 286 message.append(" FAIL"); 287 } 288 message.append("\n"); 289 message.append("Errors at"); 290 } 291 message.append(" ["); 292 message.append(Integer.toString(i)); 293 message.append("]"); 294 } 295 } 296 assertFalse("Incorrect output for checkFastDistanceFloat3Float3Float" + 297 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 298 } 299 checkFastDistanceFloat4Float4Float()300 private void checkFastDistanceFloat4Float4Float() { 301 Allocation inLeftVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xb38263al, false); 302 Allocation inRightVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x50873543l, false); 303 try { 304 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 305 script.set_gAllocInRightVector(inRightVector); 306 script.forEach_testFastDistanceFloat4Float4Float(inLeftVector, out); 307 verifyResultsFastDistanceFloat4Float4Float(inLeftVector, inRightVector, out, false); 308 } catch (Exception e) { 309 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFastDistanceFloat4Float4Float: " + e.toString()); 310 } 311 try { 312 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 313 scriptRelaxed.set_gAllocInRightVector(inRightVector); 314 scriptRelaxed.forEach_testFastDistanceFloat4Float4Float(inLeftVector, out); 315 verifyResultsFastDistanceFloat4Float4Float(inLeftVector, inRightVector, out, true); 316 } catch (Exception e) { 317 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFastDistanceFloat4Float4Float: " + e.toString()); 318 } 319 } 320 verifyResultsFastDistanceFloat4Float4Float(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed)321 private void verifyResultsFastDistanceFloat4Float4Float(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed) { 322 float[] arrayInLeftVector = new float[INPUTSIZE * 4]; 323 Arrays.fill(arrayInLeftVector, (float) 42); 324 inLeftVector.copyTo(arrayInLeftVector); 325 float[] arrayInRightVector = new float[INPUTSIZE * 4]; 326 Arrays.fill(arrayInRightVector, (float) 42); 327 inRightVector.copyTo(arrayInRightVector); 328 float[] arrayOut = new float[INPUTSIZE * 1]; 329 Arrays.fill(arrayOut, (float) 42); 330 out.copyTo(arrayOut); 331 StringBuilder message = new StringBuilder(); 332 boolean errorFound = false; 333 for (int i = 0; i < INPUTSIZE; i++) { 334 ArgumentsFloatNFloatNFloat args = new ArgumentsFloatNFloatNFloat(); 335 // Create the appropriate sized arrays in args 336 args.inLeftVector = new float[4]; 337 args.inRightVector = new float[4]; 338 // Fill args with the input values 339 for (int j = 0; j < 4 ; j++) { 340 args.inLeftVector[j] = arrayInLeftVector[i * 4 + j]; 341 } 342 for (int j = 0; j < 4 ; j++) { 343 args.inRightVector[j] = arrayInRightVector[i * 4 + j]; 344 } 345 Target target = new Target(Target.FunctionType.FAST, Target.ReturnType.FLOAT, relaxed); 346 CoreMathVerifier.computeFastDistance(args, target); 347 348 // Compare the expected outputs to the actual values returned by RS. 349 boolean valid = true; 350 if (!args.out.couldBe(arrayOut[i])) { 351 valid = false; 352 } 353 if (!valid) { 354 if (!errorFound) { 355 errorFound = true; 356 for (int j = 0; j < 4 ; j++) { 357 message.append("Input inLeftVector: "); 358 appendVariableToMessage(message, arrayInLeftVector[i * 4 + j]); 359 message.append("\n"); 360 } 361 for (int j = 0; j < 4 ; j++) { 362 message.append("Input inRightVector: "); 363 appendVariableToMessage(message, arrayInRightVector[i * 4 + j]); 364 message.append("\n"); 365 } 366 message.append("Expected output out: "); 367 appendVariableToMessage(message, args.out); 368 message.append("\n"); 369 message.append("Actual output out: "); 370 appendVariableToMessage(message, arrayOut[i]); 371 if (!args.out.couldBe(arrayOut[i])) { 372 message.append(" FAIL"); 373 } 374 message.append("\n"); 375 message.append("Errors at"); 376 } 377 message.append(" ["); 378 message.append(Integer.toString(i)); 379 message.append("]"); 380 } 381 } 382 assertFalse("Incorrect output for checkFastDistanceFloat4Float4Float" + 383 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 384 } 385 testFastDistance()386 public void testFastDistance() { 387 checkFastDistanceFloatFloatFloat(); 388 checkFastDistanceFloat2Float2Float(); 389 checkFastDistanceFloat3Float3Float(); 390 checkFastDistanceFloat4Float4Float(); 391 } 392 } 393