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 TestNativePowr extends RSBaseCompute { 26 27 private ScriptC_TestNativePowr script; 28 private ScriptC_TestNativePowrRelaxed scriptRelaxed; 29 30 @Override 31 protected void setUp() throws Exception { 32 super.setUp(); 33 script = new ScriptC_TestNativePowr(mRS); 34 scriptRelaxed = new ScriptC_TestNativePowrRelaxed(mRS); 35 } 36 37 public class ArgumentsFloatFloatFloat { 38 public float inV; 39 public float inY; 40 public Target.Floaty out; 41 } 42 43 private void checkNativePowrFloatFloatFloat() { 44 Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x3c3550bdff7a10c2l, 0, 256); 45 Allocation inY = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x3c3550bdff7a10c5l, -15, 15); 46 try { 47 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 48 script.set_gAllocInY(inY); 49 script.forEach_testNativePowrFloatFloatFloat(inV, out); 50 verifyResultsNativePowrFloatFloatFloat(inV, inY, out, false); 51 } catch (Exception e) { 52 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativePowrFloatFloatFloat: " + e.toString()); 53 } 54 try { 55 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 56 scriptRelaxed.set_gAllocInY(inY); 57 scriptRelaxed.forEach_testNativePowrFloatFloatFloat(inV, out); 58 verifyResultsNativePowrFloatFloatFloat(inV, inY, out, true); 59 } catch (Exception e) { 60 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativePowrFloatFloatFloat: " + e.toString()); 61 } 62 } 63 64 private void verifyResultsNativePowrFloatFloatFloat(Allocation inV, Allocation inY, Allocation out, boolean relaxed) { 65 float[] arrayInV = new float[INPUTSIZE * 1]; 66 inV.copyTo(arrayInV); 67 float[] arrayInY = new float[INPUTSIZE * 1]; 68 inY.copyTo(arrayInY); 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.inV = arrayInV[i]; 76 args.inY = arrayInY[i]; 77 // Figure out what the outputs should have been. 78 Target target = new Target(relaxed); 79 CoreMathVerifier.computeNativePowr(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 inV: "); 88 message.append(String.format("%14.8g {%8x} %15a", 89 args.inV, Float.floatToRawIntBits(args.inV), args.inV)); 90 message.append("\n"); 91 message.append("Input inY: "); 92 message.append(String.format("%14.8g {%8x} %15a", 93 args.inY, Float.floatToRawIntBits(args.inY), args.inY)); 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 checkNativePowrFloatFloatFloat" + 106 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); 107 } 108 } 109 } 110 } 111 112 private void checkNativePowrFloat2Float2Float2() { 113 Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xdbc56fbe7733c926l, 0, 256); 114 Allocation inY = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xdbc56fbe7733c929l, -15, 15); 115 try { 116 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 117 script.set_gAllocInY(inY); 118 script.forEach_testNativePowrFloat2Float2Float2(inV, out); 119 verifyResultsNativePowrFloat2Float2Float2(inV, inY, out, false); 120 } catch (Exception e) { 121 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativePowrFloat2Float2Float2: " + e.toString()); 122 } 123 try { 124 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 125 scriptRelaxed.set_gAllocInY(inY); 126 scriptRelaxed.forEach_testNativePowrFloat2Float2Float2(inV, out); 127 verifyResultsNativePowrFloat2Float2Float2(inV, inY, out, true); 128 } catch (Exception e) { 129 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativePowrFloat2Float2Float2: " + e.toString()); 130 } 131 } 132 133 private void verifyResultsNativePowrFloat2Float2Float2(Allocation inV, Allocation inY, Allocation out, boolean relaxed) { 134 float[] arrayInV = new float[INPUTSIZE * 2]; 135 inV.copyTo(arrayInV); 136 float[] arrayInY = new float[INPUTSIZE * 2]; 137 inY.copyTo(arrayInY); 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.inV = arrayInV[i * 2 + j]; 145 args.inY = arrayInY[i * 2 + j]; 146 // Figure out what the outputs should have been. 147 Target target = new Target(relaxed); 148 CoreMathVerifier.computeNativePowr(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 inV: "); 157 message.append(String.format("%14.8g {%8x} %15a", 158 args.inV, Float.floatToRawIntBits(args.inV), args.inV)); 159 message.append("\n"); 160 message.append("Input inY: "); 161 message.append(String.format("%14.8g {%8x} %15a", 162 args.inY, Float.floatToRawIntBits(args.inY), args.inY)); 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 checkNativePowrFloat2Float2Float2" + 175 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); 176 } 177 } 178 } 179 } 180 181 private void checkNativePowrFloat3Float3Float3() { 182 Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x302a4dde7911cac7l, 0, 256); 183 Allocation inY = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x302a4dde7911cacal, -15, 15); 184 try { 185 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 186 script.set_gAllocInY(inY); 187 script.forEach_testNativePowrFloat3Float3Float3(inV, out); 188 verifyResultsNativePowrFloat3Float3Float3(inV, inY, out, false); 189 } catch (Exception e) { 190 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativePowrFloat3Float3Float3: " + e.toString()); 191 } 192 try { 193 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 194 scriptRelaxed.set_gAllocInY(inY); 195 scriptRelaxed.forEach_testNativePowrFloat3Float3Float3(inV, out); 196 verifyResultsNativePowrFloat3Float3Float3(inV, inY, out, true); 197 } catch (Exception e) { 198 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativePowrFloat3Float3Float3: " + e.toString()); 199 } 200 } 201 202 private void verifyResultsNativePowrFloat3Float3Float3(Allocation inV, Allocation inY, Allocation out, boolean relaxed) { 203 float[] arrayInV = new float[INPUTSIZE * 4]; 204 inV.copyTo(arrayInV); 205 float[] arrayInY = new float[INPUTSIZE * 4]; 206 inY.copyTo(arrayInY); 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.inV = arrayInV[i * 4 + j]; 214 args.inY = arrayInY[i * 4 + j]; 215 // Figure out what the outputs should have been. 216 Target target = new Target(relaxed); 217 CoreMathVerifier.computeNativePowr(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 inV: "); 226 message.append(String.format("%14.8g {%8x} %15a", 227 args.inV, Float.floatToRawIntBits(args.inV), args.inV)); 228 message.append("\n"); 229 message.append("Input inY: "); 230 message.append(String.format("%14.8g {%8x} %15a", 231 args.inY, Float.floatToRawIntBits(args.inY), args.inY)); 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 checkNativePowrFloat3Float3Float3" + 244 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); 245 } 246 } 247 } 248 } 249 250 private void checkNativePowrFloat4Float4Float4() { 251 Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x848f2bfe7aefcc68l, 0, 256); 252 Allocation inY = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x848f2bfe7aefcc6bl, -15, 15); 253 try { 254 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 255 script.set_gAllocInY(inY); 256 script.forEach_testNativePowrFloat4Float4Float4(inV, out); 257 verifyResultsNativePowrFloat4Float4Float4(inV, inY, out, false); 258 } catch (Exception e) { 259 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativePowrFloat4Float4Float4: " + e.toString()); 260 } 261 try { 262 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 263 scriptRelaxed.set_gAllocInY(inY); 264 scriptRelaxed.forEach_testNativePowrFloat4Float4Float4(inV, out); 265 verifyResultsNativePowrFloat4Float4Float4(inV, inY, out, true); 266 } catch (Exception e) { 267 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativePowrFloat4Float4Float4: " + e.toString()); 268 } 269 } 270 271 private void verifyResultsNativePowrFloat4Float4Float4(Allocation inV, Allocation inY, Allocation out, boolean relaxed) { 272 float[] arrayInV = new float[INPUTSIZE * 4]; 273 inV.copyTo(arrayInV); 274 float[] arrayInY = new float[INPUTSIZE * 4]; 275 inY.copyTo(arrayInY); 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.inV = arrayInV[i * 4 + j]; 283 args.inY = arrayInY[i * 4 + j]; 284 // Figure out what the outputs should have been. 285 Target target = new Target(relaxed); 286 CoreMathVerifier.computeNativePowr(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 inV: "); 295 message.append(String.format("%14.8g {%8x} %15a", 296 args.inV, Float.floatToRawIntBits(args.inV), args.inV)); 297 message.append("\n"); 298 message.append("Input inY: "); 299 message.append(String.format("%14.8g {%8x} %15a", 300 args.inY, Float.floatToRawIntBits(args.inY), args.inY)); 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 checkNativePowrFloat4Float4Float4" + 313 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); 314 } 315 } 316 } 317 } 318 319 public void testNativePowr() { 320 checkNativePowrFloatFloatFloat(); 321 checkNativePowrFloat2Float2Float2(); 322 checkNativePowrFloat3Float3Float3(); 323 checkNativePowrFloat4Float4Float4(); 324 } 325 } 326