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