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