/tests/tests/renderscript/src/android/renderscript/cts/generated/TestRemainder.java

https://gitlab.com/chprasanna93/platform_cts · Java · 716 lines · 650 code · 26 blank · 40 comment · 48 complexity · b6abc376563530e182aba49274c8e438 MD5 · raw file

  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. // Don't edit this file! It is auto-generated by frameworks/rs/api/generate.sh.
  17. package android.renderscript.cts;
  18. import android.renderscript.Allocation;
  19. import android.renderscript.RSRuntimeException;
  20. import android.renderscript.Element;
  21. import android.renderscript.cts.Target;
  22. import java.util.Arrays;
  23. public class TestRemainder extends RSBaseCompute {
  24. private ScriptC_TestRemainder script;
  25. private ScriptC_TestRemainderRelaxed scriptRelaxed;
  26. @Override
  27. protected void setUp() throws Exception {
  28. super.setUp();
  29. script = new ScriptC_TestRemainder(mRS);
  30. scriptRelaxed = new ScriptC_TestRemainderRelaxed(mRS);
  31. }
  32. public class ArgumentsFloatFloatFloat {
  33. public float inNumerator;
  34. public float inDenominator;
  35. public Target.Floaty out;
  36. }
  37. private void checkRemainderFloatFloatFloat() {
  38. Allocation inNumerator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x317ea229l, false);
  39. Allocation inDenominator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xe2ebe35al, false);
  40. try {
  41. Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
  42. script.set_gAllocInDenominator(inDenominator);
  43. script.forEach_testRemainderFloatFloatFloat(inNumerator, out);
  44. verifyResultsRemainderFloatFloatFloat(inNumerator, inDenominator, out, false);
  45. } catch (Exception e) {
  46. throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemainderFloatFloatFloat: " + e.toString());
  47. }
  48. try {
  49. Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
  50. scriptRelaxed.set_gAllocInDenominator(inDenominator);
  51. scriptRelaxed.forEach_testRemainderFloatFloatFloat(inNumerator, out);
  52. verifyResultsRemainderFloatFloatFloat(inNumerator, inDenominator, out, true);
  53. } catch (Exception e) {
  54. throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemainderFloatFloatFloat: " + e.toString());
  55. }
  56. }
  57. private void verifyResultsRemainderFloatFloatFloat(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed) {
  58. float[] arrayInNumerator = new float[INPUTSIZE * 1];
  59. Arrays.fill(arrayInNumerator, (float) 42);
  60. inNumerator.copyTo(arrayInNumerator);
  61. float[] arrayInDenominator = new float[INPUTSIZE * 1];
  62. Arrays.fill(arrayInDenominator, (float) 42);
  63. inDenominator.copyTo(arrayInDenominator);
  64. float[] arrayOut = new float[INPUTSIZE * 1];
  65. Arrays.fill(arrayOut, (float) 42);
  66. out.copyTo(arrayOut);
  67. StringBuilder message = new StringBuilder();
  68. boolean errorFound = false;
  69. for (int i = 0; i < INPUTSIZE; i++) {
  70. for (int j = 0; j < 1 ; j++) {
  71. // Extract the inputs.
  72. ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
  73. args.inNumerator = arrayInNumerator[i];
  74. args.inDenominator = arrayInDenominator[i];
  75. // Figure out what the outputs should have been.
  76. Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
  77. CoreMathVerifier.computeRemainder(args, target);
  78. // Validate the outputs.
  79. boolean valid = true;
  80. if (!args.out.couldBe(arrayOut[i * 1 + j])) {
  81. valid = false;
  82. }
  83. if (!valid) {
  84. if (!errorFound) {
  85. errorFound = true;
  86. message.append("Input inNumerator: ");
  87. appendVariableToMessage(message, args.inNumerator);
  88. message.append("\n");
  89. message.append("Input inDenominator: ");
  90. appendVariableToMessage(message, args.inDenominator);
  91. message.append("\n");
  92. message.append("Expected output out: ");
  93. appendVariableToMessage(message, args.out);
  94. message.append("\n");
  95. message.append("Actual output out: ");
  96. appendVariableToMessage(message, arrayOut[i * 1 + j]);
  97. if (!args.out.couldBe(arrayOut[i * 1 + j])) {
  98. message.append(" FAIL");
  99. }
  100. message.append("\n");
  101. message.append("Errors at");
  102. }
  103. message.append(" [");
  104. message.append(Integer.toString(i));
  105. message.append(", ");
  106. message.append(Integer.toString(j));
  107. message.append("]");
  108. }
  109. }
  110. }
  111. assertFalse("Incorrect output for checkRemainderFloatFloatFloat" +
  112. (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
  113. }
  114. private void checkRemainderFloat2Float2Float2() {
  115. Allocation inNumerator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x3fdcf8d5l, false);
  116. Allocation inDenominator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xaa4be3a6l, false);
  117. try {
  118. Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
  119. script.set_gAllocInDenominator(inDenominator);
  120. script.forEach_testRemainderFloat2Float2Float2(inNumerator, out);
  121. verifyResultsRemainderFloat2Float2Float2(inNumerator, inDenominator, out, false);
  122. } catch (Exception e) {
  123. throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemainderFloat2Float2Float2: " + e.toString());
  124. }
  125. try {
  126. Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
  127. scriptRelaxed.set_gAllocInDenominator(inDenominator);
  128. scriptRelaxed.forEach_testRemainderFloat2Float2Float2(inNumerator, out);
  129. verifyResultsRemainderFloat2Float2Float2(inNumerator, inDenominator, out, true);
  130. } catch (Exception e) {
  131. throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemainderFloat2Float2Float2: " + e.toString());
  132. }
  133. }
  134. private void verifyResultsRemainderFloat2Float2Float2(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed) {
  135. float[] arrayInNumerator = new float[INPUTSIZE * 2];
  136. Arrays.fill(arrayInNumerator, (float) 42);
  137. inNumerator.copyTo(arrayInNumerator);
  138. float[] arrayInDenominator = new float[INPUTSIZE * 2];
  139. Arrays.fill(arrayInDenominator, (float) 42);
  140. inDenominator.copyTo(arrayInDenominator);
  141. float[] arrayOut = new float[INPUTSIZE * 2];
  142. Arrays.fill(arrayOut, (float) 42);
  143. out.copyTo(arrayOut);
  144. StringBuilder message = new StringBuilder();
  145. boolean errorFound = false;
  146. for (int i = 0; i < INPUTSIZE; i++) {
  147. for (int j = 0; j < 2 ; j++) {
  148. // Extract the inputs.
  149. ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
  150. args.inNumerator = arrayInNumerator[i * 2 + j];
  151. args.inDenominator = arrayInDenominator[i * 2 + j];
  152. // Figure out what the outputs should have been.
  153. Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
  154. CoreMathVerifier.computeRemainder(args, target);
  155. // Validate the outputs.
  156. boolean valid = true;
  157. if (!args.out.couldBe(arrayOut[i * 2 + j])) {
  158. valid = false;
  159. }
  160. if (!valid) {
  161. if (!errorFound) {
  162. errorFound = true;
  163. message.append("Input inNumerator: ");
  164. appendVariableToMessage(message, args.inNumerator);
  165. message.append("\n");
  166. message.append("Input inDenominator: ");
  167. appendVariableToMessage(message, args.inDenominator);
  168. message.append("\n");
  169. message.append("Expected output out: ");
  170. appendVariableToMessage(message, args.out);
  171. message.append("\n");
  172. message.append("Actual output out: ");
  173. appendVariableToMessage(message, arrayOut[i * 2 + j]);
  174. if (!args.out.couldBe(arrayOut[i * 2 + j])) {
  175. message.append(" FAIL");
  176. }
  177. message.append("\n");
  178. message.append("Errors at");
  179. }
  180. message.append(" [");
  181. message.append(Integer.toString(i));
  182. message.append(", ");
  183. message.append(Integer.toString(j));
  184. message.append("]");
  185. }
  186. }
  187. }
  188. assertFalse("Incorrect output for checkRemainderFloat2Float2Float2" +
  189. (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
  190. }
  191. private void checkRemainderFloat3Float3Float3() {
  192. Allocation inNumerator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xe2a8e4d6l, false);
  193. Allocation inDenominator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x7d2776dfl, false);
  194. try {
  195. Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
  196. script.set_gAllocInDenominator(inDenominator);
  197. script.forEach_testRemainderFloat3Float3Float3(inNumerator, out);
  198. verifyResultsRemainderFloat3Float3Float3(inNumerator, inDenominator, out, false);
  199. } catch (Exception e) {
  200. throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemainderFloat3Float3Float3: " + e.toString());
  201. }
  202. try {
  203. Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
  204. scriptRelaxed.set_gAllocInDenominator(inDenominator);
  205. scriptRelaxed.forEach_testRemainderFloat3Float3Float3(inNumerator, out);
  206. verifyResultsRemainderFloat3Float3Float3(inNumerator, inDenominator, out, true);
  207. } catch (Exception e) {
  208. throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemainderFloat3Float3Float3: " + e.toString());
  209. }
  210. }
  211. private void verifyResultsRemainderFloat3Float3Float3(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed) {
  212. float[] arrayInNumerator = new float[INPUTSIZE * 4];
  213. Arrays.fill(arrayInNumerator, (float) 42);
  214. inNumerator.copyTo(arrayInNumerator);
  215. float[] arrayInDenominator = new float[INPUTSIZE * 4];
  216. Arrays.fill(arrayInDenominator, (float) 42);
  217. inDenominator.copyTo(arrayInDenominator);
  218. float[] arrayOut = new float[INPUTSIZE * 4];
  219. Arrays.fill(arrayOut, (float) 42);
  220. out.copyTo(arrayOut);
  221. StringBuilder message = new StringBuilder();
  222. boolean errorFound = false;
  223. for (int i = 0; i < INPUTSIZE; i++) {
  224. for (int j = 0; j < 3 ; j++) {
  225. // Extract the inputs.
  226. ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
  227. args.inNumerator = arrayInNumerator[i * 4 + j];
  228. args.inDenominator = arrayInDenominator[i * 4 + j];
  229. // Figure out what the outputs should have been.
  230. Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
  231. CoreMathVerifier.computeRemainder(args, target);
  232. // Validate the outputs.
  233. boolean valid = true;
  234. if (!args.out.couldBe(arrayOut[i * 4 + j])) {
  235. valid = false;
  236. }
  237. if (!valid) {
  238. if (!errorFound) {
  239. errorFound = true;
  240. message.append("Input inNumerator: ");
  241. appendVariableToMessage(message, args.inNumerator);
  242. message.append("\n");
  243. message.append("Input inDenominator: ");
  244. appendVariableToMessage(message, args.inDenominator);
  245. message.append("\n");
  246. message.append("Expected output out: ");
  247. appendVariableToMessage(message, args.out);
  248. message.append("\n");
  249. message.append("Actual output out: ");
  250. appendVariableToMessage(message, arrayOut[i * 4 + j]);
  251. if (!args.out.couldBe(arrayOut[i * 4 + j])) {
  252. message.append(" FAIL");
  253. }
  254. message.append("\n");
  255. message.append("Errors at");
  256. }
  257. message.append(" [");
  258. message.append(Integer.toString(i));
  259. message.append(", ");
  260. message.append(Integer.toString(j));
  261. message.append("]");
  262. }
  263. }
  264. }
  265. assertFalse("Incorrect output for checkRemainderFloat3Float3Float3" +
  266. (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
  267. }
  268. private void checkRemainderFloat4Float4Float4() {
  269. Allocation inNumerator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x8574d0d7l, false);
  270. Allocation inDenominator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x50030a18l, false);
  271. try {
  272. Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
  273. script.set_gAllocInDenominator(inDenominator);
  274. script.forEach_testRemainderFloat4Float4Float4(inNumerator, out);
  275. verifyResultsRemainderFloat4Float4Float4(inNumerator, inDenominator, out, false);
  276. } catch (Exception e) {
  277. throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemainderFloat4Float4Float4: " + e.toString());
  278. }
  279. try {
  280. Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
  281. scriptRelaxed.set_gAllocInDenominator(inDenominator);
  282. scriptRelaxed.forEach_testRemainderFloat4Float4Float4(inNumerator, out);
  283. verifyResultsRemainderFloat4Float4Float4(inNumerator, inDenominator, out, true);
  284. } catch (Exception e) {
  285. throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemainderFloat4Float4Float4: " + e.toString());
  286. }
  287. }
  288. private void verifyResultsRemainderFloat4Float4Float4(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed) {
  289. float[] arrayInNumerator = new float[INPUTSIZE * 4];
  290. Arrays.fill(arrayInNumerator, (float) 42);
  291. inNumerator.copyTo(arrayInNumerator);
  292. float[] arrayInDenominator = new float[INPUTSIZE * 4];
  293. Arrays.fill(arrayInDenominator, (float) 42);
  294. inDenominator.copyTo(arrayInDenominator);
  295. float[] arrayOut = new float[INPUTSIZE * 4];
  296. Arrays.fill(arrayOut, (float) 42);
  297. out.copyTo(arrayOut);
  298. StringBuilder message = new StringBuilder();
  299. boolean errorFound = false;
  300. for (int i = 0; i < INPUTSIZE; i++) {
  301. for (int j = 0; j < 4 ; j++) {
  302. // Extract the inputs.
  303. ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
  304. args.inNumerator = arrayInNumerator[i * 4 + j];
  305. args.inDenominator = arrayInDenominator[i * 4 + j];
  306. // Figure out what the outputs should have been.
  307. Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
  308. CoreMathVerifier.computeRemainder(args, target);
  309. // Validate the outputs.
  310. boolean valid = true;
  311. if (!args.out.couldBe(arrayOut[i * 4 + j])) {
  312. valid = false;
  313. }
  314. if (!valid) {
  315. if (!errorFound) {
  316. errorFound = true;
  317. message.append("Input inNumerator: ");
  318. appendVariableToMessage(message, args.inNumerator);
  319. message.append("\n");
  320. message.append("Input inDenominator: ");
  321. appendVariableToMessage(message, args.inDenominator);
  322. message.append("\n");
  323. message.append("Expected output out: ");
  324. appendVariableToMessage(message, args.out);
  325. message.append("\n");
  326. message.append("Actual output out: ");
  327. appendVariableToMessage(message, arrayOut[i * 4 + j]);
  328. if (!args.out.couldBe(arrayOut[i * 4 + j])) {
  329. message.append(" FAIL");
  330. }
  331. message.append("\n");
  332. message.append("Errors at");
  333. }
  334. message.append(" [");
  335. message.append(Integer.toString(i));
  336. message.append(", ");
  337. message.append(Integer.toString(j));
  338. message.append("]");
  339. }
  340. }
  341. }
  342. assertFalse("Incorrect output for checkRemainderFloat4Float4Float4" +
  343. (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
  344. }
  345. public class ArgumentsHalfHalfHalf {
  346. public short inNumerator;
  347. public double inNumeratorDouble;
  348. public short inDenominator;
  349. public double inDenominatorDouble;
  350. public Target.Floaty out;
  351. }
  352. private void checkRemainderHalfHalfHalf() {
  353. Allocation inNumerator = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0xcd987ebel, false);
  354. Allocation inDenominator = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x59b61387l, false);
  355. try {
  356. Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
  357. script.set_gAllocInDenominator(inDenominator);
  358. script.forEach_testRemainderHalfHalfHalf(inNumerator, out);
  359. verifyResultsRemainderHalfHalfHalf(inNumerator, inDenominator, out, false);
  360. } catch (Exception e) {
  361. throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemainderHalfHalfHalf: " + e.toString());
  362. }
  363. try {
  364. Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
  365. scriptRelaxed.set_gAllocInDenominator(inDenominator);
  366. scriptRelaxed.forEach_testRemainderHalfHalfHalf(inNumerator, out);
  367. verifyResultsRemainderHalfHalfHalf(inNumerator, inDenominator, out, true);
  368. } catch (Exception e) {
  369. throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemainderHalfHalfHalf: " + e.toString());
  370. }
  371. }
  372. private void verifyResultsRemainderHalfHalfHalf(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed) {
  373. short[] arrayInNumerator = new short[INPUTSIZE * 1];
  374. Arrays.fill(arrayInNumerator, (short) 42);
  375. inNumerator.copyTo(arrayInNumerator);
  376. short[] arrayInDenominator = new short[INPUTSIZE * 1];
  377. Arrays.fill(arrayInDenominator, (short) 42);
  378. inDenominator.copyTo(arrayInDenominator);
  379. short[] arrayOut = new short[INPUTSIZE * 1];
  380. Arrays.fill(arrayOut, (short) 42);
  381. out.copyTo(arrayOut);
  382. StringBuilder message = new StringBuilder();
  383. boolean errorFound = false;
  384. for (int i = 0; i < INPUTSIZE; i++) {
  385. for (int j = 0; j < 1 ; j++) {
  386. // Extract the inputs.
  387. ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf();
  388. args.inNumerator = arrayInNumerator[i];
  389. args.inNumeratorDouble = Float16Utils.convertFloat16ToDouble(args.inNumerator);
  390. args.inDenominator = arrayInDenominator[i];
  391. args.inDenominatorDouble = Float16Utils.convertFloat16ToDouble(args.inDenominator);
  392. // Figure out what the outputs should have been.
  393. Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
  394. CoreMathVerifier.computeRemainder(args, target);
  395. // Validate the outputs.
  396. boolean valid = true;
  397. if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]))) {
  398. valid = false;
  399. }
  400. if (!valid) {
  401. if (!errorFound) {
  402. errorFound = true;
  403. message.append("Input inNumerator: ");
  404. appendVariableToMessage(message, args.inNumerator);
  405. message.append("\n");
  406. message.append("Input inDenominator: ");
  407. appendVariableToMessage(message, args.inDenominator);
  408. message.append("\n");
  409. message.append("Expected output out: ");
  410. appendVariableToMessage(message, args.out);
  411. message.append("\n");
  412. message.append("Actual output out: ");
  413. appendVariableToMessage(message, arrayOut[i * 1 + j]);
  414. message.append("\n");
  415. message.append("Actual output out (in double): ");
  416. appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]));
  417. if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]))) {
  418. message.append(" FAIL");
  419. }
  420. message.append("\n");
  421. message.append("Errors at");
  422. }
  423. message.append(" [");
  424. message.append(Integer.toString(i));
  425. message.append(", ");
  426. message.append(Integer.toString(j));
  427. message.append("]");
  428. }
  429. }
  430. }
  431. assertFalse("Incorrect output for checkRemainderHalfHalfHalf" +
  432. (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
  433. }
  434. private void checkRemainderHalf2Half2Half2() {
  435. Allocation inNumerator = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0x3b2e47fel, false);
  436. Allocation inDenominator = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0xd890a2c7l, false);
  437. try {
  438. Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE);
  439. script.set_gAllocInDenominator(inDenominator);
  440. script.forEach_testRemainderHalf2Half2Half2(inNumerator, out);
  441. verifyResultsRemainderHalf2Half2Half2(inNumerator, inDenominator, out, false);
  442. } catch (Exception e) {
  443. throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemainderHalf2Half2Half2: " + e.toString());
  444. }
  445. try {
  446. Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE);
  447. scriptRelaxed.set_gAllocInDenominator(inDenominator);
  448. scriptRelaxed.forEach_testRemainderHalf2Half2Half2(inNumerator, out);
  449. verifyResultsRemainderHalf2Half2Half2(inNumerator, inDenominator, out, true);
  450. } catch (Exception e) {
  451. throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemainderHalf2Half2Half2: " + e.toString());
  452. }
  453. }
  454. private void verifyResultsRemainderHalf2Half2Half2(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed) {
  455. short[] arrayInNumerator = new short[INPUTSIZE * 2];
  456. Arrays.fill(arrayInNumerator, (short) 42);
  457. inNumerator.copyTo(arrayInNumerator);
  458. short[] arrayInDenominator = new short[INPUTSIZE * 2];
  459. Arrays.fill(arrayInDenominator, (short) 42);
  460. inDenominator.copyTo(arrayInDenominator);
  461. short[] arrayOut = new short[INPUTSIZE * 2];
  462. Arrays.fill(arrayOut, (short) 42);
  463. out.copyTo(arrayOut);
  464. StringBuilder message = new StringBuilder();
  465. boolean errorFound = false;
  466. for (int i = 0; i < INPUTSIZE; i++) {
  467. for (int j = 0; j < 2 ; j++) {
  468. // Extract the inputs.
  469. ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf();
  470. args.inNumerator = arrayInNumerator[i * 2 + j];
  471. args.inNumeratorDouble = Float16Utils.convertFloat16ToDouble(args.inNumerator);
  472. args.inDenominator = arrayInDenominator[i * 2 + j];
  473. args.inDenominatorDouble = Float16Utils.convertFloat16ToDouble(args.inDenominator);
  474. // Figure out what the outputs should have been.
  475. Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
  476. CoreMathVerifier.computeRemainder(args, target);
  477. // Validate the outputs.
  478. boolean valid = true;
  479. if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) {
  480. valid = false;
  481. }
  482. if (!valid) {
  483. if (!errorFound) {
  484. errorFound = true;
  485. message.append("Input inNumerator: ");
  486. appendVariableToMessage(message, args.inNumerator);
  487. message.append("\n");
  488. message.append("Input inDenominator: ");
  489. appendVariableToMessage(message, args.inDenominator);
  490. message.append("\n");
  491. message.append("Expected output out: ");
  492. appendVariableToMessage(message, args.out);
  493. message.append("\n");
  494. message.append("Actual output out: ");
  495. appendVariableToMessage(message, arrayOut[i * 2 + j]);
  496. message.append("\n");
  497. message.append("Actual output out (in double): ");
  498. appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]));
  499. if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) {
  500. message.append(" FAIL");
  501. }
  502. message.append("\n");
  503. message.append("Errors at");
  504. }
  505. message.append(" [");
  506. message.append(Integer.toString(i));
  507. message.append(", ");
  508. message.append(Integer.toString(j));
  509. message.append("]");
  510. }
  511. }
  512. }
  513. assertFalse("Incorrect output for checkRemainderHalf2Half2Half2" +
  514. (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
  515. }
  516. private void checkRemainderHalf3Half3Half3() {
  517. Allocation inNumerator = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0x86a0786dl, false);
  518. Allocation inDenominator = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0xc450747el, false);
  519. try {
  520. Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE);
  521. script.set_gAllocInDenominator(inDenominator);
  522. script.forEach_testRemainderHalf3Half3Half3(inNumerator, out);
  523. verifyResultsRemainderHalf3Half3Half3(inNumerator, inDenominator, out, false);
  524. } catch (Exception e) {
  525. throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemainderHalf3Half3Half3: " + e.toString());
  526. }
  527. try {
  528. Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE);
  529. scriptRelaxed.set_gAllocInDenominator(inDenominator);
  530. scriptRelaxed.forEach_testRemainderHalf3Half3Half3(inNumerator, out);
  531. verifyResultsRemainderHalf3Half3Half3(inNumerator, inDenominator, out, true);
  532. } catch (Exception e) {
  533. throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemainderHalf3Half3Half3: " + e.toString());
  534. }
  535. }
  536. private void verifyResultsRemainderHalf3Half3Half3(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed) {
  537. short[] arrayInNumerator = new short[INPUTSIZE * 4];
  538. Arrays.fill(arrayInNumerator, (short) 42);
  539. inNumerator.copyTo(arrayInNumerator);
  540. short[] arrayInDenominator = new short[INPUTSIZE * 4];
  541. Arrays.fill(arrayInDenominator, (short) 42);
  542. inDenominator.copyTo(arrayInDenominator);
  543. short[] arrayOut = new short[INPUTSIZE * 4];
  544. Arrays.fill(arrayOut, (short) 42);
  545. out.copyTo(arrayOut);
  546. StringBuilder message = new StringBuilder();
  547. boolean errorFound = false;
  548. for (int i = 0; i < INPUTSIZE; i++) {
  549. for (int j = 0; j < 3 ; j++) {
  550. // Extract the inputs.
  551. ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf();
  552. args.inNumerator = arrayInNumerator[i * 4 + j];
  553. args.inNumeratorDouble = Float16Utils.convertFloat16ToDouble(args.inNumerator);
  554. args.inDenominator = arrayInDenominator[i * 4 + j];
  555. args.inDenominatorDouble = Float16Utils.convertFloat16ToDouble(args.inDenominator);
  556. // Figure out what the outputs should have been.
  557. Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
  558. CoreMathVerifier.computeRemainder(args, target);
  559. // Validate the outputs.
  560. boolean valid = true;
  561. if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
  562. valid = false;
  563. }
  564. if (!valid) {
  565. if (!errorFound) {
  566. errorFound = true;
  567. message.append("Input inNumerator: ");
  568. appendVariableToMessage(message, args.inNumerator);
  569. message.append("\n");
  570. message.append("Input inDenominator: ");
  571. appendVariableToMessage(message, args.inDenominator);
  572. message.append("\n");
  573. message.append("Expected output out: ");
  574. appendVariableToMessage(message, args.out);
  575. message.append("\n");
  576. message.append("Actual output out: ");
  577. appendVariableToMessage(message, arrayOut[i * 4 + j]);
  578. message.append("\n");
  579. message.append("Actual output out (in double): ");
  580. appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]));
  581. if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
  582. message.append(" FAIL");
  583. }
  584. message.append("\n");
  585. message.append("Errors at");
  586. }
  587. message.append(" [");
  588. message.append(Integer.toString(i));
  589. message.append(", ");
  590. message.append(Integer.toString(j));
  591. message.append("]");
  592. }
  593. }
  594. }
  595. assertFalse("Incorrect output for checkRemainderHalf3Half3Half3" +
  596. (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
  597. }
  598. private void checkRemainderHalf4Half4Half4() {
  599. Allocation inNumerator = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0xd212a8dcl, false);
  600. Allocation inDenominator = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0xb0104635l, false);
  601. try {
  602. Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE);
  603. script.set_gAllocInDenominator(inDenominator);
  604. script.forEach_testRemainderHalf4Half4Half4(inNumerator, out);
  605. verifyResultsRemainderHalf4Half4Half4(inNumerator, inDenominator, out, false);
  606. } catch (Exception e) {
  607. throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemainderHalf4Half4Half4: " + e.toString());
  608. }
  609. try {
  610. Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE);
  611. scriptRelaxed.set_gAllocInDenominator(inDenominator);
  612. scriptRelaxed.forEach_testRemainderHalf4Half4Half4(inNumerator, out);
  613. verifyResultsRemainderHalf4Half4Half4(inNumerator, inDenominator, out, true);
  614. } catch (Exception e) {
  615. throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemainderHalf4Half4Half4: " + e.toString());
  616. }
  617. }
  618. private void verifyResultsRemainderHalf4Half4Half4(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed) {
  619. short[] arrayInNumerator = new short[INPUTSIZE * 4];
  620. Arrays.fill(arrayInNumerator, (short) 42);
  621. inNumerator.copyTo(arrayInNumerator);
  622. short[] arrayInDenominator = new short[INPUTSIZE * 4];
  623. Arrays.fill(arrayInDenominator, (short) 42);
  624. inDenominator.copyTo(arrayInDenominator);
  625. short[] arrayOut = new short[INPUTSIZE * 4];
  626. Arrays.fill(arrayOut, (short) 42);
  627. out.copyTo(arrayOut);
  628. StringBuilder message = new StringBuilder();
  629. boolean errorFound = false;
  630. for (int i = 0; i < INPUTSIZE; i++) {
  631. for (int j = 0; j < 4 ; j++) {
  632. // Extract the inputs.
  633. ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf();
  634. args.inNumerator = arrayInNumerator[i * 4 + j];
  635. args.inNumeratorDouble = Float16Utils.convertFloat16ToDouble(args.inNumerator);
  636. args.inDenominator = arrayInDenominator[i * 4 + j];
  637. args.inDenominatorDouble = Float16Utils.convertFloat16ToDouble(args.inDenominator);
  638. // Figure out what the outputs should have been.
  639. Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
  640. CoreMathVerifier.computeRemainder(args, target);
  641. // Validate the outputs.
  642. boolean valid = true;
  643. if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
  644. valid = false;
  645. }
  646. if (!valid) {
  647. if (!errorFound) {
  648. errorFound = true;
  649. message.append("Input inNumerator: ");
  650. appendVariableToMessage(message, args.inNumerator);
  651. message.append("\n");
  652. message.append("Input inDenominator: ");
  653. appendVariableToMessage(message, args.inDenominator);
  654. message.append("\n");
  655. message.append("Expected output out: ");
  656. appendVariableToMessage(message, args.out);
  657. message.append("\n");
  658. message.append("Actual output out: ");
  659. appendVariableToMessage(message, arrayOut[i * 4 + j]);
  660. message.append("\n");
  661. message.append("Actual output out (in double): ");
  662. appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]));
  663. if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
  664. message.append(" FAIL");
  665. }
  666. message.append("\n");
  667. message.append("Errors at");
  668. }
  669. message.append(" [");
  670. message.append(Integer.toString(i));
  671. message.append(", ");
  672. message.append(Integer.toString(j));
  673. message.append("]");
  674. }
  675. }
  676. }
  677. assertFalse("Incorrect output for checkRemainderHalf4Half4Half4" +
  678. (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
  679. }
  680. public void testRemainder() {
  681. checkRemainderFloatFloatFloat();
  682. checkRemainderFloat2Float2Float2();
  683. checkRemainderFloat3Float3Float3();
  684. checkRemainderFloat4Float4Float4();
  685. checkRemainderHalfHalfHalf();
  686. checkRemainderHalf2Half2Half2();
  687. checkRemainderHalf3Half3Half3();
  688. checkRemainderHalf4Half4Half4();
  689. }
  690. }