removing modules not ready for release
diff --git a/commons-numbers-complex-streams/LICENSE b/commons-numbers-complex-streams/LICENSE
deleted file mode 100644
index 261eeb9..0000000
--- a/commons-numbers-complex-streams/LICENSE
+++ /dev/null
@@ -1,201 +0,0 @@
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
diff --git a/commons-numbers-complex-streams/NOTICE b/commons-numbers-complex-streams/NOTICE
deleted file mode 100644
index c1a3017..0000000
--- a/commons-numbers-complex-streams/NOTICE
+++ /dev/null
@@ -1,6 +0,0 @@
-Apache Commons Numbers
-Copyright 2001-2021 The Apache Software Foundation
-
-This product includes software developed at
-The Apache Software Foundation (http://www.apache.org/).
-
diff --git a/commons-numbers-complex-streams/README.md b/commons-numbers-complex-streams/README.md
deleted file mode 100644
index dbd9451..0000000
--- a/commons-numbers-complex-streams/README.md
+++ /dev/null
@@ -1,105 +0,0 @@
-<!---
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<!---
- +======================================================================+
- |**** ****|
- |**** THIS FILE IS GENERATED BY THE COMMONS BUILD PLUGIN ****|
- |**** DO NOT EDIT DIRECTLY ****|
- |**** ****|
- +======================================================================+
- | TEMPLATE FILE: readme-md-template.md |
- | commons-build-plugin/trunk/src/main/resources/commons-xdoc-templates |
- +======================================================================+
- | |
- | 1) Re-generate using: mvn commons-build:readme-md |
- | |
- | 2) Set the following properties in the component's pom: |
- | - commons.componentid (required, alphabetic, lower case) |
- | - commons.release.version (required) |
- | |
- | 3) Example Properties |
- | |
- | <properties> |
- | <commons.componentid>math</commons.componentid> |
- | <commons.release.version>1.2</commons.release.version> |
- | </properties> |
- | |
- +======================================================================+
---->
-Apache Commons Numbers Complex Streams
-===================
-
-[![Build Status](https://travis-ci.org/apache/commons-numbers.svg)](https://travis-ci.org/apache/commons-numbers)
-[![Coverage Status](https://coveralls.io/repos/apache/commons-numbers/badge.svg)](https://coveralls.io/r/apache/commons-numbers)
-[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-numbers-complex-streams/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-numbers-complex-streams/)
-[![Javadocs](https://javadoc.io/badge/org.apache.commons/commons-numbers-complex-streams/1.0-beta1.svg)](https://javadoc.io/doc/org.apache.commons/commons-numbers-complex-streams/1.0-beta1)
-
-Arrays, streams and collections of complex numbers.
-
-Documentation
--------------
-
-More information can be found on the [Apache Commons Numbers homepage](https://commons.apache.org/proper/commons-numbers).
-The [Javadoc](https://commons.apache.org/proper/commons-numbers/commons-numbers-complex-streams/apidocs) can be browsed.
-Questions related to the usage of Apache Commons Numbers should be posted to the [user mailing list][ml].
-
-Where can I get the latest release?
------------------------------------
-You can download source and binaries from our [download page](https://commons.apache.org/proper/commons-numbers/download_numbers.cgi).
-
-Alternatively you can pull it from the central Maven repositories:
-
-```xml
-<dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-numbers-complex-streams</artifactId>
- <version>1.0</version>
-</dependency>
-```
-
-Contributing
-------------
-
-We accept Pull Requests via GitHub. The [developer mailing list][ml] is the main channel of communication for contributors.
-There are some guidelines which will make applying PRs easier for us:
-+ No tabs! Please use spaces for indentation.
-+ Respect the code style.
-+ Create minimal diffs - disable on save actions like reformat source code or organize imports. If you feel the source code should be reformatted create a separate PR for this change.
-+ Provide JUnit tests for your changes and make sure your changes don't break any existing tests by running ```mvn clean test```.
-
-If you plan to contribute on a regular basis, please consider filing a [contributor license agreement](https://www.apache.org/licenses/#clas).
-You can learn more about contributing via GitHub in our [contribution guidelines](CONTRIBUTING.md).
-
-License
--------
-This code is under the [Apache Licence v2](https://www.apache.org/licenses/LICENSE-2.0).
-
-See the `NOTICE` file for required notices and attributions.
-
-Donations
----------
-You like Apache Commons Numbers? Then [donate back to the ASF](https://www.apache.org/foundation/contributing.html) to support the development.
-
-Additional Resources
---------------------
-
-+ [Apache Commons Homepage](https://commons.apache.org/)
-+ [Apache Issue Tracker (JIRA)](https://issues.apache.org/jira/browse/NUMBERS)
-+ [Apache Commons Twitter Account](https://twitter.com/ApacheCommons)
-+ `#apache-commons` IRC channel on `irc.freenode.org`
-
-[ml]:https://commons.apache.org/mail-lists.html
diff --git a/commons-numbers-complex-streams/pom.xml b/commons-numbers-complex-streams/pom.xml
deleted file mode 100644
index 4478fca..0000000
--- a/commons-numbers-complex-streams/pom.xml
+++ /dev/null
@@ -1,65 +0,0 @@
-<?xml version="1.0"?>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
- xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-numbers-parent</artifactId>
- <version>1.0</version>
- </parent>
-
- <artifactId>commons-numbers-complex-streams</artifactId>
- <name>Apache Commons Numbers Complex Streams</name>
-
- <description>Arrays, streams and collections of complex numbers.</description>
-
- <properties>
- <!-- The Java Module System Name -->
- <commons.module.name>org.apache.commons.numbers.complex.streams</commons.module.name>
- <!-- This value must reflect the current name of the base package. -->
- <commons.osgi.symbolicName>org.apache.commons.numbers.complex.streams</commons.osgi.symbolicName>
- <!-- OSGi -->
- <commons.osgi.export>org.apache.commons.numbers.complex.streams</commons.osgi.export>
- <!-- Workaround to avoid duplicating config files. -->
- <numbers.parent.dir>${basedir}/..</numbers.parent.dir>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-numbers-complex</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-numbers-core</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-math3</artifactId>
- <scope>test</scope>
- </dependency>
-
- </dependencies>
-
-</project>
diff --git a/commons-numbers-complex-streams/src/main/java/org/apache/commons/numbers/complex/streams/ComplexUtils.java b/commons-numbers-complex-streams/src/main/java/org/apache/commons/numbers/complex/streams/ComplexUtils.java
deleted file mode 100644
index fcd1975..0000000
--- a/commons-numbers-complex-streams/src/main/java/org/apache/commons/numbers/complex/streams/ComplexUtils.java
+++ /dev/null
@@ -1,1624 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.numbers.complex.streams;
-
-import org.apache.commons.numbers.complex.Complex;
-
-/**
- * Static implementations of common {@link Complex} utilities functions.
- */
-public final class ComplexUtils {
- /** Dimension X. */
- private static final int DIM_X = 0;
- /** Dimension Y. */
- private static final int DIM_Y = 1;
- /** Dimension Z. */
- private static final int DIM_Z = 2;
-
- /**
- * Utility class.
- */
- private ComplexUtils() {}
-
- /**
- * Creates a complex number from the given polar representation.
- * <p>
- * If either {@code r} or {@code theta} is NaN, or {@code theta} is
- * infinite, {@code Complex(NaN, NaN)} is returned.
- * <p>
- * If {@code r} is infinite and {@code theta} is finite, infinite or NaN
- * values may be returned in parts of the result, following the rules for
- * double arithmetic.
- *
- * Examples:
- * <pre>
- * {@code
- * polar2Complex(INFINITY, \(\pi\)) = INFINITY + INFINITY i
- * polar2Complex(INFINITY, 0) = INFINITY + NaN i
- * polar2Complex(INFINITY, \(-\frac{\pi}{4}\)) = INFINITY - INFINITY i
- * polar2Complex(INFINITY, \(5\frac{\pi}{4}\)) = -INFINITY - INFINITY i }
- * </pre>
- *
- * @param r the modulus of the complex number to create
- * @param theta the argument of the complex number to create
- * @return {@code Complex}
- * @throws IllegalArgumentException if {@code r} is negative
- */
- public static Complex polar2Complex(double r, double theta) {
- if (r < 0) {
- throw new NegativeModulusException(r);
- }
- return Complex.ofCartesian(r * Math.cos(theta), r * Math.sin(theta));
- }
-
- /**
- * Creates {@code Complex[]} array given {@code double[]} arrays of r and
- * theta.
- *
- * @param r {@code double[]} of moduli
- * @param theta {@code double[]} of arguments
- * @return {@code Complex[]}
- * @throws IllegalArgumentException if any element in {@code r} is negative
- */
- public static Complex[] polar2Complex(double[] r, double[] theta) {
- final int length = r.length;
- final Complex[] c = new Complex[length];
- for (int x = 0; x < length; x++) {
- if (r[x] < 0) {
- throw new NegativeModulusException(r[x]);
- }
- c[x] = Complex.ofCartesian(r[x] * Math.cos(theta[x]), r[x] * Math.sin(theta[x]));
- }
- return c;
- }
-
- /**
- * Creates {@code Complex[][]} array given {@code double[][]} arrays of r
- * and theta.
- *
- * @param r {@code double[]} of moduli
- * @param theta {@code double[]} of arguments
- * @return {@code Complex[][]}
- * @throws IllegalArgumentException if any element in {@code r} is negative
- */
- public static Complex[][] polar2Complex(double[][] r, double[][] theta) {
- final int length = r.length;
- final Complex[][] c = new Complex[length][];
- for (int x = 0; x < length; x++) {
- c[x] = polar2Complex(r[x], theta[x]);
- }
- return c;
- }
-
- /**
- * Creates {@code Complex[][][]} array given {@code double[][][]} arrays of
- * r and theta.
- *
- * @param r array of moduli
- * @param theta array of arguments
- * @return {@code Complex}
- * @throws IllegalArgumentException if any element in {@code r} is negative
- */
- public static Complex[][][] polar2Complex(double[][][] r, double[][][] theta) {
- final int length = r.length;
- final Complex[][][] c = new Complex[length][][];
- for (int x = 0; x < length; x++) {
- c[x] = polar2Complex(r[x], theta[x]);
- }
- return c;
- }
-
- /**
- * Returns double from array {@code real[]} at entry {@code index} as a
- * {@code Complex}.
- *
- * @param real array of real numbers
- * @param index location in the array
- * @return {@code Complex}.
- */
- public static Complex extractComplexFromRealArray(double[] real, int index) {
- return Complex.ofCartesian(real[index], 0);
- }
-
- /**
- * Returns float from array {@code real[]} at entry {@code index} as a
- * {@code Complex}.
- *
- * @param real array of real numbers
- * @param index location in the array
- * @return {@code Complex} array
- */
- public static Complex extractComplexFromRealArray(float[] real, int index) {
- return Complex.ofCartesian(real[index], 0);
- }
-
- /**
- * Returns double from array {@code imaginary[]} at entry {@code index} as a
- * {@code Complex}.
- *
- * @param imaginary array of imaginary numbers
- * @param index location in the array
- * @return {@code Complex} array
- */
- public static Complex extractComplexFromImaginaryArray(double[] imaginary, int index) {
- return Complex.ofCartesian(0, imaginary[index]);
- }
-
- /**
- * Returns float from array {@code imaginary[]} at entry {@code index} as a
- * {@code Complex}.
- *
- * @param imaginary array of imaginary numbers
- * @param index location in the array
- * @return {@code Complex} array
- */
- public static Complex extractComplexFromImaginaryArray(float[] imaginary, int index) {
- return Complex.ofCartesian(0, imaginary[index]);
- }
-
- /**
- * Returns real component of Complex from array {@code Complex[]} at entry
- * {@code index} as a {@code double}.
- *
- * @param complex array of complex numbers
- * @param index location in the array
- * @return {@code double}.
- */
- public static double extractRealFromComplexArray(Complex[] complex, int index) {
- return complex[index].getReal();
- }
-
- /**
- * Returns real component of array {@code Complex[]} at entry {@code index}
- * as a {@code float}.
- *
- * @param complex array of complex numbers
- * @param index location in the array
- * @return {@code float}.
- */
- public static float extractRealFloatFromComplexArray(Complex[] complex, int index) {
- return (float) complex[index].getReal();
- }
-
- /**
- * Returns imaginary component of Complex from array {@code Complex[]} at
- * entry {@code index} as a {@code double}.
- *
- * @param complex array of complex numbers
- * @param index location in the array
- * @return {@code double}.
- */
- public static double extractImaginaryFromComplexArray(Complex[] complex, int index) {
- return complex[index].getImaginary();
- }
-
- /**
- * Returns imaginary component of array {@code Complex[]} at entry
- * {@code index} as a {@code float}.
- *
- * @param complex array of complex numbers
- * @param index location in the array
- * @return {@code float}.
- */
- public static float extractImaginaryFloatFromComplexArray(Complex[] complex, int index) {
- return (float) complex[index].getImaginary();
- }
-
- /**
- * Returns a Complex object from interleaved {@code double[]} array at entry
- * {@code index}.
- *
- * @param d array of interleaved complex numbers alternating real and imaginary values
- * @param index location in the array This is the location by complex number, e.g. index number 5 in the
- * array will return {@code Complex.ofCartesian(d[10], d[11])}
- * @return {@code Complex}.
- */
- public static Complex extractComplexFromInterleavedArray(double[] d, int index) {
- return Complex.ofCartesian(d[index * 2], d[index * 2 + 1]);
- }
-
- /**
- * Returns a Complex object from interleaved {@code float[]} array at entry
- * {@code index}.
- *
- * @param f float array of interleaved complex numbers alternating real and imaginary values
- * @param index location in the array This is the location by complex number, e.g. index number 5
- * in the {@code float[]} array will return new {@code Complex(d[10], d[11])}
- * @return {@code Complex}.
- */
- public static Complex extractComplexFromInterleavedArray(float[] f, int index) {
- return Complex.ofCartesian(f[index * 2], f[index * 2 + 1]);
- }
-
- /**
- * Returns values of Complex object from array {@code Complex[]} at entry
- * {@code index} as a size 2 {@code double} of the form {real, imag}.
- *
- * @param complex array of complex numbers
- * @param index location in the array
- * @return size 2 array.
- */
- public static double[] extractInterleavedFromComplexArray(Complex[] complex, int index) {
- return new double[] {complex[index].getReal(), complex[index].getImaginary()};
- }
-
- /**
- * Returns Complex object from array {@code Complex[]} at entry
- * {@code index} as a size 2 {@code float} of the form {real, imag}.
- *
- * @param complex {@code Complex} array
- * @param index location in the array
- * @return size 2 {@code float[]}.
- */
- public static float[] extractInterleavedFloatFromComplexArray(Complex[] complex, int index) {
- return new float[] {(float) complex[index].getReal(), (float) complex[index].getImaginary()};
- }
-
- /**
- * Converts a {@code double[]} array to a {@code Complex[]} array.
- *
- * @param real array of numbers to be converted to their {@code Complex} equivalent
- * @return {@code Complex} array
- */
- public static Complex[] real2Complex(double[] real) {
- int index = 0;
- final Complex[] c = new Complex[real.length];
- for (final double d : real) {
- c[index] = Complex.ofCartesian(d, 0);
- index++;
- }
- return c;
- }
-
- /**
- * Converts a {@code float[]} array to a {@code Complex[]} array.
- *
- * @param real array of numbers to be converted to their {@code Complex} equivalent
- * @return {@code Complex} array
- */
- public static Complex[] real2Complex(float[] real) {
- int index = 0;
- final Complex[] c = new Complex[real.length];
- for (final float d : real) {
- c[index] = Complex.ofCartesian(d, 0);
- index++;
- }
- return c;
- }
-
- /**
- * Converts a 2D real {@code double[][]} array to a 2D {@code Complex[][]}
- * array.
- *
- * @param d 2D array
- * @return 2D {@code Complex} array
- */
- public static Complex[][] real2Complex(double[][] d) {
- final int w = d.length;
- final Complex[][] c = new Complex[w][];
- for (int n = 0; n < w; n++) {
- c[n] = ComplexUtils.real2Complex(d[n]);
- }
- return c;
- }
-
- /**
- * Converts a 2D real {@code float[][]} array to a 2D {@code Complex[][]}
- * array.
- *
- * @param d 2D array
- * @return 2D {@code Complex} array
- */
- public static Complex[][] real2Complex(float[][] d) {
- final int w = d.length;
- final Complex[][] c = new Complex[w][];
- for (int n = 0; n < w; n++) {
- c[n] = ComplexUtils.real2Complex(d[n]);
- }
- return c;
- }
-
- /**
- * Converts a 3D real {@code double[][][]} array to a {@code Complex [][][]}
- * array.
- *
- * @param d 3D complex interleaved array
- * @return 3D {@code Complex} array
- */
- public static Complex[][][] real2Complex(double[][][] d) {
- final int w = d.length;
- final Complex[][][] c = new Complex[w][][];
- for (int x = 0; x < w; x++) {
- c[x] = ComplexUtils.real2Complex(d[x]);
- }
- return c;
- }
-
- /**
- * Converts a 3D real {@code float[][][]} array to a {@code Complex [][][]}
- * array.
- *
- * @param d 3D complex interleaved array
- * @return 3D {@code Complex} array
- */
- public static Complex[][][] real2Complex(float[][][] d) {
- final int w = d.length;
- final Complex[][][] c = new Complex[w][][];
- for (int x = 0; x < w; x++) {
- c[x] = ComplexUtils.real2Complex(d[x]);
- }
- return c;
- }
-
- /**
- * Converts a 4D real {@code double[][][][]} array to a {@code Complex [][][][]}
- * array.
- *
- * @param d 4D complex interleaved array
- * @return 4D {@code Complex} array
- */
- public static Complex[][][][] real2Complex(double[][][][] d) {
- final int w = d.length;
- final Complex[][][][] c = new Complex[w][][][];
- for (int x = 0; x < w; x++) {
- c[x] = ComplexUtils.real2Complex(d[x]);
- }
- return c;
- }
-
- /**
- * Converts real component of {@code Complex[]} array to a {@code double[]}
- * array.
- *
- * @param c {@code Complex} array
- * @return array of the real component
- */
- public static double[] complex2Real(Complex[] c) {
- int index = 0;
- final double[] d = new double[c.length];
- for (final Complex cc : c) {
- d[index] = cc.getReal();
- index++;
- }
- return d;
- }
-
- /**
- * Converts real component of {@code Complex[]} array to a {@code float[]}
- * array.
- *
- * @param c {@code Complex} array
- * @return {@code float[]} array of the real component
- */
- public static float[] complex2RealFloat(Complex[] c) {
- int index = 0;
- final float[] f = new float[c.length];
- for (final Complex cc : c) {
- f[index] = (float) cc.getReal();
- index++;
- }
- return f;
- }
-
- /**
- * Converts real component of a 2D {@code Complex[][]} array to a 2D
- * {@code double[][]} array.
- *
- * @param c 2D {@code Complex} array
- * @return {@code double[][]} of real component
- */
- public static double[][] complex2Real(Complex[][] c) {
- final int length = c.length;
- final double[][] d = new double[length][];
- for (int n = 0; n < length; n++) {
- d[n] = complex2Real(c[n]);
- }
- return d;
- }
-
- /**
- * Converts real component of a 2D {@code Complex[][]} array to a 2D
- * {@code float[][]} array.
- *
- * @param c 2D {@code Complex} array
- * @return {@code float[][]} of real component
- */
- public static float[][] complex2RealFloat(Complex[][] c) {
- final int length = c.length;
- final float[][] f = new float[length][];
- for (int n = 0; n < length; n++) {
- f[n] = complex2RealFloat(c[n]);
- }
- return f;
- }
-
- /**
- * Converts real component of a 3D {@code Complex[][][]} array to a 3D
- * {@code double[][][]} array.
- *
- * @param c 3D complex interleaved array
- * @return array of real component
- */
- public static double[][][] complex2Real(Complex[][][] c) {
- final int length = c.length;
- final double[][][] d = new double[length][][];
- for (int n = 0; n < length; n++) {
- d[n] = complex2Real(c[n]);
- }
- return d;
- }
-
- /**
- * Converts real component of a 3D {@code Complex[][][]} array to a 3D
- * {@code float[][][]} array.
- *
- * @param c 3D {@code Complex} array
- * @return {@code float[][][]} of real component
- */
- public static float[][][] complex2RealFloat(Complex[][][] c) {
- final int length = c.length;
- final float[][][] f = new float[length][][];
- for (int n = 0; n < length; n++) {
- f[n] = complex2RealFloat(c[n]);
- }
- return f;
- }
-
- /**
- * Converts real component of a 4D {@code Complex[][][][]} array to a 4D
- * {@code double[][][][]} array.
- *
- * @param c 4D complex interleaved array
- * @return array of real component
- */
- public static double[][][][] complex2Real(Complex[][][][] c) {
- final int length = c.length;
- final double[][][][] d = new double[length][][][];
- for (int n = 0; n < length; n++) {
- d[n] = complex2Real(c[n]);
- }
- return d;
- }
-
- /**
- * Converts real component of a 4D {@code Complex[][][][]} array to a 4D
- * {@code float[][][][]} array.
- *
- * @param c 4D {@code Complex} array
- * @return {@code float[][][][]} of real component
- */
- public static float[][][][] complex2RealFloat(Complex[][][][] c) {
- final int length = c.length;
- final float[][][][] f = new float[length][][][];
- for (int n = 0; n < length; n++) {
- f[n] = complex2RealFloat(c[n]);
- }
- return f;
- }
-
- /**
- * Converts a {@code double[]} array to an imaginary {@code Complex[]}
- * array.
- *
- * @param imaginary array of numbers to be converted to their {@code Complex} equivalent
- * @return {@code Complex} array
- */
- public static Complex[] imaginary2Complex(double[] imaginary) {
- int index = 0;
- final Complex[] c = new Complex[imaginary.length];
- for (final double d : imaginary) {
- c[index] = Complex.ofCartesian(0, d);
- index++;
- }
- return c;
- }
-
- /**
- * Converts a {@code float[]} array to an imaginary {@code Complex[]} array.
- *
- * @param imaginary array of numbers to be converted to their {@code Complex} equivalent
- * @return {@code Complex} array
- */
- public static Complex[] imaginary2Complex(float[] imaginary) {
- int index = 0;
- final Complex[] c = new Complex[imaginary.length];
- for (final float d : imaginary) {
- c[index] = Complex.ofCartesian(0, d);
- index++;
- }
- return c;
- }
-
- /**
- * Converts a 2D imaginary array {@code double[][]} to a 2D
- * {@code Complex[][]} array.
- *
- * @param i 2D array
- * @return 2D {@code Complex} array
- */
- public static Complex[][] imaginary2Complex(double[][] i) {
- final int w = i.length;
- final Complex[][] c = new Complex[w][];
- for (int n = 0; n < w; n++) {
- c[n] = ComplexUtils.imaginary2Complex(i[n]);
- }
- return c;
- }
-
- /**
- * Converts a 3D imaginary array {@code double[][][]} to a {@code Complex[]}
- * array.
- *
- * @param i 3D complex imaginary array
- * @return 3D {@code Complex} array
- */
- public static Complex[][][] imaginary2Complex(double[][][] i) {
- final int w = i.length;
- final Complex[][][] c = new Complex[w][][];
- for (int n = 0; n < w; n++) {
- c[n] = ComplexUtils.imaginary2Complex(i[n]);
- }
- return c;
- }
-
- /**
- * Converts a 4D imaginary array {@code double[][][][]} to a 4D {@code Complex[][][][]}
- * array.
- *
- * @param i 4D complex imaginary array
- * @return 4D {@code Complex} array
- */
- public static Complex[][][][] imaginary2Complex(double[][][][] i) {
- final int w = i.length;
- final Complex[][][][] c = new Complex[w][][][];
- for (int n = 0; n < w; n++) {
- c[n] = ComplexUtils.imaginary2Complex(i[n]);
- }
- return c;
- }
-
- /**
- * Converts imaginary part of a {@code Complex[]} array to a
- * {@code double[]} array.
- *
- * @param c {@code Complex} array.
- * @return array of the imaginary component
- */
- public static double[] complex2Imaginary(Complex[] c) {
- int index = 0;
- final double[] i = new double[c.length];
- for (final Complex cc : c) {
- i[index] = cc.getImaginary();
- index++;
- }
- return i;
- }
-
- /**
- * Converts imaginary component of a {@code Complex[]} array to a
- * {@code float[]} array.
- *
- * @param c {@code Complex} array.
- * @return {@code float[]} array of the imaginary component
- */
- public static float[] complex2ImaginaryFloat(Complex[] c) {
- int index = 0;
- final float[] f = new float[c.length];
- for (final Complex cc : c) {
- f[index] = (float) cc.getImaginary();
- index++;
- }
- return f;
- }
-
- /**
- * Converts imaginary component of a 2D {@code Complex[][]} array to a 2D
- * {@code double[][]} array.
- *
- * @param c 2D {@code Complex} array
- * @return {@code double[][]} of imaginary component
- */
- public static double[][] complex2Imaginary(Complex[][] c) {
- final int length = c.length;
- final double[][] i = new double[length][];
- for (int n = 0; n < length; n++) {
- i[n] = complex2Imaginary(c[n]);
- }
- return i;
- }
-
- /**
- * Converts imaginary component of a 2D {@code Complex[][]} array to a 2D
- * {@code float[][]} array.
- *
- * @param c 2D {@code Complex} array
- * @return {@code float[][]} of imaginary component
- */
- public static float[][] complex2ImaginaryFloat(Complex[][] c) {
- final int length = c.length;
- final float[][] f = new float[length][];
- for (int n = 0; n < length; n++) {
- f[n] = complex2ImaginaryFloat(c[n]);
- }
- return f;
- }
-
- /**
- * Converts imaginary component of a 3D {@code Complex[][][]} array to a 3D
- * {@code double[][][]} array.
- *
- * @param c 3D complex interleaved array
- * @return 3D {@code Complex} array
- */
- public static double[][][] complex2Imaginary(Complex[][][] c) {
- final int length = c.length;
- final double[][][] i = new double[length][][];
- for (int n = 0; n < length; n++) {
- i[n] = complex2Imaginary(c[n]);
- }
- return i;
- }
-
- /**
- * Converts imaginary component of a 3D {@code Complex[][][]} array to a 3D
- * {@code float[][][]} array.
- *
- * @param c 3D {@code Complex} array
- * @return {@code float[][][]} of imaginary component
- */
- public static float[][][] complex2ImaginaryFloat(Complex[][][] c) {
- final int length = c.length;
- final float[][][] f = new float[length][][];
- for (int n = 0; n < length; n++) {
- f[n] = complex2ImaginaryFloat(c[n]);
- }
- return f;
- }
-
- /**
- * Converts imaginary component of a 4D {@code Complex[][][][]} array to a 4D
- * {@code double[][][][]} array.
- *
- * @param c 4D complex interleaved array
- * @return 4D {@code Complex} array
- */
- public static double[][][][] complex2Imaginary(Complex[][][][] c) {
- final int length = c.length;
- final double[][][][] i = new double[length][][][];
- for (int n = 0; n < length; n++) {
- i[n] = complex2Imaginary(c[n]);
- }
- return i;
- }
-
- /**
- * Converts imaginary component of a 4D {@code Complex[][][][]} array to a 4D
- * {@code float[][][][]} array.
- *
- * @param c 4D {@code Complex} array
- * @return {@code float[][][][]} of imaginary component
- */
- public static float[][][][] complex2ImaginaryFloat(Complex[][][][] c) {
- final int length = c.length;
- final float[][][][] f = new float[length][][][];
- for (int n = 0; n < length; n++) {
- f[n] = complex2ImaginaryFloat(c[n]);
- }
- return f;
- }
-
- // INTERLEAVED METHODS
-
- /**
- * Converts a complex interleaved {@code double[]} array to a
- * {@code Complex[]} array.
- *
- * @param interleaved array of numbers to be converted to their {@code Complex} equivalent
- * @return {@code Complex} array
- */
- public static Complex[] interleaved2Complex(double[] interleaved) {
- final int length = interleaved.length / 2;
- final Complex[] c = new Complex[length];
- for (int n = 0; n < length; n++) {
- c[n] = Complex.ofCartesian(interleaved[n * 2], interleaved[n * 2 + 1]);
- }
- return c;
- }
-
- /**
- * Converts a complex interleaved {@code float[]} array to a
- * {@code Complex[]} array.
- *
- * @param interleaved float[] array of numbers to be converted to their {@code Complex} equivalent
- * @return {@code Complex} array
- */
- public static Complex[] interleaved2Complex(float[] interleaved) {
- final int length = interleaved.length / 2;
- final Complex[] c = new Complex[length];
- for (int n = 0; n < length; n++) {
- c[n] = Complex.ofCartesian(interleaved[n * 2], interleaved[n * 2 + 1]);
- }
- return c;
- }
-
- /**
- * Converts a {@code Complex[]} array to an interleaved complex
- * {@code double[]} array.
- *
- * @param c Complex array
- * @return complex interleaved array alternating real and
- * imaginary values
- */
- public static double[] complex2Interleaved(Complex[] c) {
- int index = 0;
- final double[] i = new double[c.length * 2];
- for (final Complex cc : c) {
- final int real = index * 2;
- final int imag = index * 2 + 1;
- i[real] = cc.getReal();
- i[imag] = cc.getImaginary();
- index++;
- }
- return i;
- }
-
- /**
- * Converts a {@code Complex[]} array to an interleaved complex
- * {@code float[]} array.
- *
- * @param c Complex array
- * @return complex interleaved {@code float[]} alternating real and
- * imaginary values
- */
- public static float[] complex2InterleavedFloat(Complex[] c) {
- int index = 0;
- final float[] f = new float[c.length * 2];
- for (final Complex cc : c) {
- final int real = index * 2;
- final int imag = index * 2 + 1;
- f[real] = (float) cc.getReal();
- f[imag] = (float) cc.getImaginary();
- index++;
- }
- return f;
- }
-
- /**
- * Converts a 2D {@code Complex[][]} array to an interleaved complex
- * {@code double[][]} array.
- *
- * @param c 2D Complex array
- * @param interleavedDim Depth level of the array to interleave
- * @return complex interleaved array alternating real and
- * imaginary values
- * @throws IllegalArgumentException if {@code interleavedDim} is not 0 or 1
- */
- public static double[][] complex2Interleaved(Complex[][] c, int interleavedDim) {
- if (interleavedDim > 1 || interleavedDim < 0) {
- throw new IndexOutOfRangeException(interleavedDim);
- }
- final int w = c.length;
- final int h = c[0].length;
- double[][] i;
- if (interleavedDim == 0) {
- i = new double[2 * w][h];
- for (int x = 0; x < w; x++) {
- for (int y = 0; y < h; y++) {
- i[x * 2][y] = c[x][y].getReal();
- i[x * 2 + 1][y] = c[x][y].getImaginary();
- }
- }
- } else {
- i = new double[w][2 * h];
- for (int x = 0; x < w; x++) {
- for (int y = 0; y < h; y++) {
- i[x][y * 2] = c[x][y].getReal();
- i[x][y * 2 + 1] = c[x][y].getImaginary();
- }
- }
- }
- return i;
- }
-
- /**
- * Converts a 2D {@code Complex[][]} array to an interleaved complex
- * {@code double[][]} array. The second d level of the array is assumed
- * to be interleaved.
- *
- * @param c 2D Complex array
- * @return complex interleaved array alternating real and
- * imaginary values
- */
- public static double[][] complex2Interleaved(Complex[][] c) {
- return complex2Interleaved(c, 1);
- }
-
- /**
- * Converts a 3D {@code Complex[][][]} array to an interleaved complex
- * {@code double[][][]} array.
- *
- * @param c 3D Complex array
- * @param interleavedDim Depth level of the array to interleave
- * @return complex interleaved array alternating real and
- * imaginary values
- * @throws IllegalArgumentException if {@code interleavedDim} is not 0, 1, or 2
- */
- public static double[][][] complex2Interleaved(Complex[][][] c, int interleavedDim) {
- if (interleavedDim > 2 || interleavedDim < 0) {
- throw new IndexOutOfRangeException(interleavedDim);
- }
- final int w = c.length;
- final int h = c[0].length;
- final int d = c[0][0].length;
- double[][][] i;
- if (interleavedDim == 0) {
- i = new double[2 * w][h][d];
- for (int x = 0; x < w; x++) {
- for (int y = 0; y < h; y++) {
- for (int z = 0; z < d; z++) {
- i[x * 2][y][z] = c[x][y][z].getReal();
- i[x * 2 + 1][y][z] = c[x][y][z].getImaginary();
- }
- }
- }
- } else if (interleavedDim == 1) {
- i = new double[w][2 * h][d];
- for (int x = 0; x < w; x++) {
- for (int y = 0; y < h; y++) {
- for (int z = 0; z < d; z++) {
- i[x][y * 2][z] = c[x][y][z].getReal();
- i[x][y * 2 + 1][z] = c[x][y][z].getImaginary();
- }
- }
- }
- } else {
- i = new double[w][h][2 * d];
- for (int x = 0; x < w; x++) {
- for (int y = 0; y < h; y++) {
- for (int z = 0; z < d; z++) {
- i[x][y][z * 2] = c[x][y][z].getReal();
- i[x][y][z * 2 + 1] = c[x][y][z].getImaginary();
- }
- }
- }
- }
- return i;
- }
-
- /**
- * Converts a 4D {@code Complex[][][][]} array to an interleaved complex
- * {@code double[][][][]} array.
- *
- * @param c 4D Complex array
- * @param interleavedDim Depth level of the array to interleave
- * @return complex interleaved array alternating real and
- * imaginary values
- * @throws IllegalArgumentException if {@code interleavedDim} is not in the range {@code [0, 3]}
- */
- public static double[][][][] complex2Interleaved(Complex[][][][] c, int interleavedDim) {
- if (interleavedDim > 3 || interleavedDim < 0) {
- throw new IndexOutOfRangeException(interleavedDim);
- }
- final int w = c.length;
- final int h = c[0].length;
- final int d = c[0][0].length;
- final int v = c[0][0][0].length;
- double[][][][] i;
- if (interleavedDim == DIM_X) {
- i = new double[2 * w][h][d][v];
- for (int x = 0; x < w; x++) {
- for (int y = 0; y < h; y++) {
- for (int z = 0; z < d; z++) {
- for (int t = 0; t < v; t++) {
- i[x * 2][y][z][t] = c[x][y][z][t].getReal();
- i[x * 2 + 1][y][z][t] = c[x][y][z][t].getImaginary();
- }
- }
- }
- }
- } else if (interleavedDim == DIM_Y) {
- i = new double[w][2 * h][d][v];
- for (int x = 0; x < w; x++) {
- for (int y = 0; y < h; y++) {
- for (int z = 0; z < d; z++) {
- for (int t = 0; t < v; t++) {
- i[x][y * 2][z][t] = c[x][y][z][t].getReal();
- i[x][y * 2 + 1][z][t] = c[x][y][z][t].getImaginary();
- }
- }
- }
- }
- } else if (interleavedDim == DIM_Z) {
- i = new double[w][h][2 * d][v];
- for (int x = 0; x < w; x++) {
- for (int y = 0; y < h; y++) {
- for (int z = 0; z < d; z++) {
- for (int t = 0; t < v; t++) {
- i[x][y][z * 2][t] = c[x][y][z][t].getReal();
- i[x][y][z * 2 + 1][t] = c[x][y][z][t].getImaginary();
- }
- }
- }
- }
- } else {
- i = new double[w][h][d][2 * v];
- for (int x = 0; x < w; x++) {
- for (int y = 0; y < h; y++) {
- for (int z = 0; z < d; z++) {
- for (int t = 0; t < v; t++) {
- i[x][y][z][t * 2] = c[x][y][z][t].getReal();
- i[x][y][z][t * 2 + 1] = c[x][y][z][t].getImaginary();
- }
- }
- }
- }
- }
- return i;
- }
-
- /**
- * Converts a 3D {@code Complex[][][]} array to an interleaved complex
- * {@code double[][][]} array. The third level of the array is
- * interleaved.
- *
- * @param c 3D Complex array
- * @return complex interleaved array alternating real and
- * imaginary values
- */
- public static double[][][] complex2Interleaved(Complex[][][] c) {
- return complex2Interleaved(c, 2);
- }
-
- /**
- * Converts a 4D {@code Complex[][][][]} array to an interleaved complex
- * {@code double[][][][]} array. The fourth level of the array is
- * interleaved.
- *
- * @param c 4D Complex array
- * @return complex interleaved array alternating real and
- * imaginary values
- */
- public static double[][][][] complex2Interleaved(Complex[][][][] c) {
- return complex2Interleaved(c, 3);
- }
-
- /**
- * Converts a 2D {@code Complex[][]} array to an interleaved complex
- * {@code float[][]} array.
- *
- * @param c 2D Complex array
- * @param interleavedDim Depth level of the array to interleave
- * @return complex interleaved {@code float[][]} alternating real and
- * imaginary values
- * @throws IllegalArgumentException if {@code interleavedDim} is not 0 or 1
- */
- public static float[][] complex2InterleavedFloat(Complex[][] c, int interleavedDim) {
- if (interleavedDim > 1 || interleavedDim < 0) {
- throw new IndexOutOfRangeException(interleavedDim);
- }
- final int w = c.length;
- final int h = c[0].length;
- float[][] i;
- if (interleavedDim == 0) {
- i = new float[2 * w][h];
- for (int x = 0; x < w; x++) {
- for (int y = 0; y < h; y++) {
- i[x * 2][y] = (float) c[x][y].getReal();
- i[x * 2 + 1][y] = (float) c[x][y].getImaginary();
- }
- }
- } else {
- i = new float[w][2 * h];
- for (int x = 0; x < w; x++) {
- for (int y = 0; y < h; y++) {
- i[x][y * 2] = (float) c[x][y].getReal();
- i[x][y * 2 + 1] = (float) c[x][y].getImaginary();
- }
- }
- }
- return i;
- }
-
- /**
- * Converts a 2D {@code Complex[][]} array to an interleaved complex
- * {@code float[][]} array. The second d level of the array is assumed
- * to be interleaved.
- *
- * @param c 2D Complex array
- *
- * @return complex interleaved {@code float[][]} alternating real and
- * imaginary values
- */
- public static float[][] complex2InterleavedFloat(Complex[][] c) {
- return complex2InterleavedFloat(c, 1);
- }
-
- /**
- * Converts a 3D {@code Complex[][][]} array to an interleaved complex
- * {@code float[][][]} array.
- *
- * @param c 3D Complex array
- * @param interleavedDim Depth level of the array to interleave
- * @return complex interleaved {@code float[][][]} alternating real and
- * imaginary values
- * @throws IllegalArgumentException if {@code interleavedDim} is not 0, 1, or 2
- */
- public static float[][][] complex2InterleavedFloat(Complex[][][] c, int interleavedDim) {
- if (interleavedDim > 2 || interleavedDim < 0) {
- throw new IndexOutOfRangeException(interleavedDim);
- }
- final int w = c.length;
- final int h = c[0].length;
- final int d = c[0][0].length;
- float[][][] i;
- if (interleavedDim == 0) {
- i = new float[2 * w][h][d];
- for (int x = 0; x < w; x++) {
- for (int y = 0; y < h; y++) {
- for (int z = 0; z < d; z++) {
- i[x * 2][y][z] = (float) c[x][y][z].getReal();
- i[x * 2 + 1][y][z] = (float) c[x][y][z].getImaginary();
- }
- }
- }
- } else if (interleavedDim == 1) {
- i = new float[w][2 * h][d];
- for (int x = 0; x < w; x++) {
- for (int y = 0; y < h; y++) {
- for (int z = 0; z < d; z++) {
- i[x][y * 2][z] = (float) c[x][y][z].getReal();
- i[x][y * 2 + 1][z] = (float) c[x][y][z].getImaginary();
- }
- }
- }
- } else {
- i = new float[w][h][2 * d];
- for (int x = 0; x < w; x++) {
- for (int y = 0; y < h; y++) {
- for (int z = 0; z < d; z++) {
- i[x][y][z * 2] = (float) c[x][y][z].getReal();
- i[x][y][z * 2 + 1] = (float) c[x][y][z].getImaginary();
- }
- }
- }
- }
- return i;
- }
-
- /**
- * Converts a 3D {@code Complex[][][]} array to an interleaved complex
- * {@code float[][][]} array. The third d level of the array is
- * interleaved.
- *
- * @param c 2D Complex array
- *
- * @return complex interleaved {@code float[][][]} alternating real and
- * imaginary values
- */
- public static float[][][] complex2InterleavedFloat(Complex[][][] c) {
- return complex2InterleavedFloat(c, 2);
- }
-
- /**
- * Converts a 2D interleaved complex {@code double[][]} array to a
- * {@code Complex[][]} array.
- *
- * @param i 2D complex interleaved array
- * @param interleavedDim Depth level of the array to interleave
- * @return 2D {@code Complex} array
- * @throws IllegalArgumentException if {@code interleavedDim} is not 0 or 1
- */
- public static Complex[][] interleaved2Complex(double[][] i, int interleavedDim) {
- if (interleavedDim > 1 || interleavedDim < 0) {
- throw new IndexOutOfRangeException(interleavedDim);
- }
- final int w = i.length;
- final int h = i[0].length;
- Complex[][] c;
- if (interleavedDim == 0) {
- c = new Complex[w / 2][h];
- for (int x = 0; x < w / 2; x++) {
- for (int y = 0; y < h; y++) {
- c[x][y] = Complex.ofCartesian(i[x * 2][y], i[x * 2 + 1][y]);
- }
- }
- } else {
- c = new Complex[w][h / 2];
- for (int x = 0; x < w; x++) {
- for (int y = 0; y < h / 2; y++) {
- c[x][y] = Complex.ofCartesian(i[x][y * 2], i[x][y * 2 + 1]);
- }
- }
- }
- return c;
- }
-
- /**
- * Converts a 2D interleaved complex {@code double[][]} array to a
- * {@code Complex[][]} array. The second d level of the array is assumed
- * to be interleaved.
- *
- * @param d 2D complex interleaved array
- * @return 2D {@code Complex} array
- */
- public static Complex[][] interleaved2Complex(double[][] d) {
- return interleaved2Complex(d, 1);
- }
-
- /**
- * Converts a 3D interleaved complex {@code double[][][]} array to a
- * {@code Complex[][][]} array.
- *
- * @param i 3D complex interleaved array
- * @param interleavedDim Depth level of the array to interleave
- * @return 3D {@code Complex} array
- * @throws IllegalArgumentException if {@code interleavedDim} is not 0, 1, or 2
- */
- public static Complex[][][] interleaved2Complex(double[][][] i, int interleavedDim) {
- if (interleavedDim > 2 || interleavedDim < 0) {
- throw new IndexOutOfRangeException(interleavedDim);
- }
- final int w = i.length;
- final int h = i[0].length;
- final int d = i[0][0].length;
- Complex[][][] c;
- if (interleavedDim == DIM_X) {
- c = new Complex[w / 2][h][d];
- for (int x = 0; x < w / 2; x++) {
- for (int y = 0; y < h; y++) {
- for (int z = 0; z < d; z++) {
- c[x][y][z] = Complex.ofCartesian(i[x * 2][y][z], i[x * 2 + 1][y][z]);
- }
- }
- }
- } else if (interleavedDim == DIM_Y) {
- c = new Complex[w][h / 2][d];
- for (int x = 0; x < w; x++) {
- for (int y = 0; y < h / 2; y++) {
- for (int z = 0; z < d; z++) {
- c[x][y][z] = Complex.ofCartesian(i[x][y * 2][z], i[x][y * 2 + 1][z]);
- }
- }
- }
- } else {
- c = new Complex[w][h][d / 2];
- for (int x = 0; x < w; x++) {
- for (int y = 0; y < h; y++) {
- for (int z = 0; z < d / 2; z++) {
- c[x][y][z] = Complex.ofCartesian(i[x][y][z * 2], i[x][y][z * 2 + 1]);
- }
- }
- }
- }
- return c;
- }
-
- /**
- * Converts a 4D interleaved complex {@code double[][][][]} array to a
- * {@code Complex[][][][]} array.
- *
- * @param i 4D complex interleaved array
- * @param interleavedDim Depth level of the array to interleave
- * @return 4D {@code Complex} array
- * @throws IllegalArgumentException if {@code interleavedDim} is not in the range {@code [0, 3]}
- */
- public static Complex[][][][] interleaved2Complex(double[][][][] i, int interleavedDim) {
- if (interleavedDim > 3 || interleavedDim < 0) {
- throw new IndexOutOfRangeException(interleavedDim);
- }
- final int w = i.length;
- final int h = i[0].length;
- final int d = i[0][0].length;
- final int v = i[0][0][0].length;
- Complex[][][][] c;
- if (interleavedDim == 0) {
- c = new Complex[w / 2][h][d][v];
- for (int x = 0; x < w / 2; x++) {
- for (int y = 0; y < h; y++) {
- for (int z = 0; z < d; z++) {
- for (int t = 0; t < v; t++) {
- c[x][y][z][t] = Complex.ofCartesian(i[x * 2][y][z][t], i[x * 2 + 1][y][z][t]);
- }
- }
- }
- }
- } else if (interleavedDim == 1) {
- c = new Complex[w][h / 2][d][v];
- for (int x = 0; x < w; x++) {
- for (int y = 0; y < h / 2; y++) {
- for (int z = 0; z < d; z++) {
- for (int t = 0; t < v; t++) {
- c[x][y][z][t] = Complex.ofCartesian(i[x][y * 2][z][t], i[x][y * 2 + 1][z][t]);
- }
- }
- }
- }
- } else if (interleavedDim == 2) {
- c = new Complex[w][h][d / 2][v];
- for (int x = 0; x < w; x++) {
- for (int y = 0; y < h; y++) {
- for (int z = 0; z < d / 2; z++) {
- for (int t = 0; t < v; t++) {
- c[x][y][z][t] = Complex.ofCartesian(i[x][y][z * 2][t], i[x][y][z * 2 + 1][t]);
- }
- }
- }
- }
- } else {
- c = new Complex[w][h][d][v / 2];
- for (int x = 0; x < w; x++) {
- for (int y = 0; y < h; y++) {
- for (int z = 0; z < d; z++) {
- for (int t = 0; t < v / 2; t++) {
- c[x][y][z][t] = Complex.ofCartesian(i[x][y][z][t * 2], i[x][y][z][t * 2 + 1]);
- }
- }
- }
- }
- }
- return c;
- }
-
- /**
- * Converts a 3D interleaved complex {@code double[][][]} array to a
- * {@code Complex[][][]} array. The third d level is assumed to be
- * interleaved.
- *
- * @param d 3D complex interleaved array
- * @return 3D {@code Complex} array
- */
- public static Complex[][][] interleaved2Complex(double[][][] d) {
- return interleaved2Complex(d, 2);
- }
-
- /**
- * Converts a 2D interleaved complex {@code float[][]} array to a
- * {@code Complex[][]} array.
- *
- * @param i 2D complex interleaved float array
- * @param interleavedDim Depth level of the array to interleave
- * @return 2D {@code Complex} array
- * @throws IllegalArgumentException if {@code interleavedDim} is not 0 or 1
- */
- public static Complex[][] interleaved2Complex(float[][] i, int interleavedDim) {
- if (interleavedDim > 1 || interleavedDim < 0) {
- throw new IndexOutOfRangeException(interleavedDim);
- }
- final int w = i.length;
- final int h = i[0].length;
- Complex[][] c;
- if (interleavedDim == 0) {
- c = new Complex[w / 2][h];
- for (int x = 0; x < w / 2; x++) {
- for (int y = 0; y < h; y++) {
- c[x][y] = Complex.ofCartesian(i[x * 2][y], i[x * 2 + 1][y]);
- }
- }
- } else {
- c = new Complex[w][h / 2];
- for (int x = 0; x < w; x++) {
- for (int y = 0; y < h / 2; y++) {
- c[x][y] = Complex.ofCartesian(i[x][y * 2], i[x][y * 2 + 1]);
- }
- }
- }
- return c;
- }
-
- /**
- * Converts a 2D interleaved complex {@code float[][]} array to a
- * {@code Complex[][]} array. The second d level of the array is assumed
- * to be interleaved.
- *
- * @param d 2D complex interleaved float array
- * @return 2D {@code Complex} array
- */
- public static Complex[][] interleaved2Complex(float[][] d) {
- return interleaved2Complex(d, 1);
- }
-
- /**
- * Converts a 3D interleaved complex {@code float[][][]} array to a
- * {@code Complex[][][]} array.
- *
- * @param i 3D complex interleaved float array
- * @param interleavedDim Depth level of the array to interleave
- * @return 3D {@code Complex} array
- * @throws IllegalArgumentException if {@code interleavedDim} is not 0, 1, or 2
- */
- public static Complex[][][] interleaved2Complex(float[][][] i, int interleavedDim) {
- if (interleavedDim > 2 || interleavedDim < 0) {
- throw new IndexOutOfRangeException(interleavedDim);
- }
- final int w = i.length;
- final int h = i[0].length;
- final int d = i[0][0].length;
- Complex[][][] c;
- if (interleavedDim == 0) {
- c = new Complex[w / 2][h][d];
- for (int x = 0; x < w / 2; x++) {
- for (int y = 0; y < h; y++) {
- for (int z = 0; z < d; z++) {
- c[x][y][z] = Complex.ofCartesian(i[x * 2][y][z], i[x * 2 + 1][y][z]);
- }
- }
- }
- } else if (interleavedDim == 1) {
- c = new Complex[w][h / 2][d];
- for (int x = 0; x < w; x++) {
- for (int y = 0; y < h / 2; y++) {
- for (int z = 0; z < d; z++) {
- c[x][y][z] = Complex.ofCartesian(i[x][y * 2][z], i[x][y * 2 + 1][z]);
- }
- }
- }
- } else {
- c = new Complex[w][h][d / 2];
- for (int x = 0; x < w; x++) {
- for (int y = 0; y < h; y++) {
- for (int z = 0; z < d / 2; z++) {
- c[x][y][z] = Complex.ofCartesian(i[x][y][z * 2], i[x][y][z * 2 + 1]);
- }
- }
- }
- }
- return c;
- }
-
- /**
- * Converts a 3D interleaved complex {@code float[][][]} array to a
- * {@code Complex[]} array. The third level of the array is assumed to
- * be interleaved.
- *
- * @param d 3D complex interleaved float array
- * @return 3D {@code Complex} array
- */
- public static Complex[][][] interleaved2Complex(float[][][] d) {
- return interleaved2Complex(d, 2);
- }
-
- // SPLIT METHODS
-
- /**
- * Converts a split complex array {@code double[] r, double[] i} to a
- * {@code Complex[]} array.
- *
- * @param real real component
- * @param imag imaginary component
- * @return {@code Complex} array
- */
- public static Complex[] split2Complex(double[] real, double[] imag) {
- final int length = real.length;
- final Complex[] c = new Complex[length];
- for (int n = 0; n < length; n++) {
- c[n] = Complex.ofCartesian(real[n], imag[n]);
- }
- return c;
- }
-
- /**
- * Converts a 2D split complex array {@code double[][] r, double[][] i} to a
- * 2D {@code Complex[][]} array.
- *
- * @param real real component
- * @param imag imaginary component
- * @return 2D {@code Complex} array
- */
- public static Complex[][] split2Complex(double[][] real, double[][] imag) {
- final int length = real.length;
- final Complex[][] c = new Complex[length][];
- for (int x = 0; x < length; x++) {
- c[x] = split2Complex(real[x], imag[x]);
- }
- return c;
- }
-
- /**
- * Converts a 3D split complex array {@code double[][][] r, double[][][] i}
- * to a 3D {@code Complex[][][]} array.
- *
- * @param real real component
- * @param imag imaginary component
- * @return 3D {@code Complex} array
- */
- public static Complex[][][] split2Complex(double[][][] real, double[][][] imag) {
- final int length = real.length;
- final Complex[][][] c = new Complex[length][][];
- for (int x = 0; x < length; x++) {
- c[x] = split2Complex(real[x], imag[x]);
- }
- return c;
- }
-
- /**
- * Converts a 4D split complex array {@code double[][][][] r, double[][][][] i}
- * to a 4D {@code Complex[][][][]} array.
- *
- * @param real real component
- * @param imag imaginary component
- * @return 4D {@code Complex} array
- */
- public static Complex[][][][] split2Complex(double[][][][] real, double[][][][] imag) {
- final int length = real.length;
- final Complex[][][][] c = new Complex[length][][][];
- for (int x = 0; x < length; x++) {
- c[x] = split2Complex(real[x], imag[x]);
- }
- return c;
- }
-
- /**
- * Converts a split complex array {@code float[] r, float[] i} to a
- * {@code Complex[]} array.
- *
- * @param real real component
- * @param imag imaginary component
- * @return {@code Complex} array
- */
- public static Complex[] split2Complex(float[] real, float[] imag) {
- final int length = real.length;
- final Complex[] c = new Complex[length];
- for (int n = 0; n < length; n++) {
- c[n] = Complex.ofCartesian(real[n], imag[n]);
- }
- return c;
- }
-
- /**
- * Converts a 2D split complex array {@code float[][] r, float[][] i} to a
- * 2D {@code Complex[][]} array.
- *
- * @param real real component
- * @param imag imaginary component
- * @return 2D {@code Complex} array
- */
- public static Complex[][] split2Complex(float[][] real, float[][] imag) {
- final int length = real.length;
- final Complex[][] c = new Complex[length][];
- for (int x = 0; x < length; x++) {
- c[x] = split2Complex(real[x], imag[x]);
- }
- return c;
- }
-
- /**
- * Converts a 3D split complex array {@code float[][][] r, float[][][] i} to
- * a 3D {@code Complex[][][]} array.
- *
- * @param real real component
- * @param imag imaginary component
- * @return 3D {@code Complex} array
- */
- public static Complex[][][] split2Complex(float[][][] real, float[][][] imag) {
- final int length = real.length;
- final Complex[][][] c = new Complex[length][][];
- for (int x = 0; x < length; x++) {
- c[x] = split2Complex(real[x], imag[x]);
- }
- return c;
- }
-
- // MISC
-
- /**
- * Initializes a {@code Complex[]} array to zero, to avoid
- * NullPointerExceptions.
- *
- * @param c Complex array
- * @return c
- */
- public static Complex[] initialize(Complex[] c) {
- final int length = c.length;
- for (int x = 0; x < length; x++) {
- c[x] = Complex.ZERO;
- }
- return c;
- }
-
- /**
- * Initializes a {@code Complex[][]} array to zero, to avoid
- * NullPointerExceptions.
- *
- * @param c {@code Complex} array
- * @return c
- */
- public static Complex[][] initialize(Complex[][] c) {
- final int length = c.length;
- for (int x = 0; x < length; x++) {
- c[x] = initialize(c[x]);
- }
- return c;
- }
-
- /**
- * Initializes a {@code Complex[][][]} array to zero, to avoid
- * NullPointerExceptions.
- *
- * @param c {@code Complex} array
- * @return c
- */
- public static Complex[][][] initialize(Complex[][][] c) {
- final int length = c.length;
- for (int x = 0; x < length; x++) {
- c[x] = initialize(c[x]);
- }
- return c;
- }
-
- /**
- * Returns {@code double[]} containing absolute values (magnitudes) of a
- * {@code Complex[]} array.
- *
- * @param c {@code Complex} array
- * @return {@code double[]}
- */
- public static double[] abs(Complex[] c) {
- final int length = c.length;
- final double[] i = new double[length];
- for (int x = 0; x < length; x++) {
- i[x] = c[x].abs();
- }
- return i;
- }
-
- /**
- * Returns {@code double[]} containing arguments (phase angles) of a
- * {@code Complex[]} array.
- *
- * @param c {@code Complex} array
- * @return {@code double[]} array
- */
- public static double[] arg(Complex[] c) {
- final int length = c.length;
- final double[] i = new double[length];
- for (int x = 0; x < length; x++) {
- i[x] = c[x].arg();
- }
- return i;
- }
-
- /**
- * Exception to be throw when a negative value is passed as the modulus.
- */
- private static class NegativeModulusException extends IllegalArgumentException {
- /** Serializable version identifier. */
- private static final long serialVersionUID = 20181205L;
-
- /**
- * @param r Wrong modulus.
- */
- NegativeModulusException(double r) {
- super("Modulus is negative: " + r);
- }
- }
-
- /**
- * Exception to be throw when an out-of-range index value is passed.
- */
- private static class IndexOutOfRangeException extends IllegalArgumentException {
- /** Serializable version identifier. */
- private static final long serialVersionUID = 20181205L;
-
- /**
- * @param i Wrong index.
- */
- IndexOutOfRangeException(int i) {
- super("Out of range: " + i);
- }
- }
-}
diff --git a/commons-numbers-complex-streams/src/main/java/org/apache/commons/numbers/complex/streams/package-info.java b/commons-numbers-complex-streams/src/main/java/org/apache/commons/numbers/complex/streams/package-info.java
deleted file mode 100644
index 0b7c1cd..0000000
--- a/commons-numbers-complex-streams/src/main/java/org/apache/commons/numbers/complex/streams/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/**
- * Complex numbers collections.
- */
-package org.apache.commons.numbers.complex.streams;
diff --git a/commons-numbers-complex-streams/src/site/resources/profile.jacoco b/commons-numbers-complex-streams/src/site/resources/profile.jacoco
deleted file mode 100644
index a12755f..0000000
--- a/commons-numbers-complex-streams/src/site/resources/profile.jacoco
+++ /dev/null
@@ -1,17 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-# -----------------------------------------------------------------------------
-#
-# Empty file used to automatically trigger JaCoCo profile from commons parent pom
diff --git a/commons-numbers-complex-streams/src/site/site.xml b/commons-numbers-complex-streams/src/site/site.xml
deleted file mode 100644
index 5a61c39..0000000
--- a/commons-numbers-complex-streams/src/site/site.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<project name="Numbers">
- <bannerRight>
- <name>Apache Commons Numbers</name>
- <src>/images/commons_numbers.small.png</src>
- <href>/index.html</href>
- </bannerRight>
-
- <body>
- <menu name="Numbers Complex Streams">
- <item name="Overview" href="index.html"/>
- <item name="Latest API docs (development)"
- href="apidocs/index.html"/>
- <!--item name="Javadoc (1.0 release)"
- href="http://commons.apache.org/rng/commons-numbers-complex-streams/javadocs/api-1.0/index.html"/-->
- </menu>
-
- </body>
-</project>
diff --git a/commons-numbers-complex-streams/src/site/xdoc/index.xml b/commons-numbers-complex-streams/src/site/xdoc/index.xml
deleted file mode 100644
index c295d95..0000000
--- a/commons-numbers-complex-streams/src/site/xdoc/index.xml
+++ /dev/null
@@ -1,40 +0,0 @@
-<?xml version="1.0"?>
-
-<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
-
-<document>
-
- <properties>
- <title>Commons Numbers Complex</title>
- </properties>
-
- <body>
-
- <section name="Apache Commons Numbers: Number types" href="summary">
- <p>
- Commons Numbers provides utilities such as complex numbers and fractions.
- </p>
-
- <p>
- The "complex-stream" module contains...
- </p>
- </section>
-
- </body>
-
-</document>
diff --git a/commons-numbers-complex-streams/src/test/java/org/apache/commons/numbers/complex/streams/ComplexUtilsTest.java b/commons-numbers-complex-streams/src/test/java/org/apache/commons/numbers/complex/streams/ComplexUtilsTest.java
deleted file mode 100644
index ffafec5..0000000
--- a/commons-numbers-complex-streams/src/test/java/org/apache/commons/numbers/complex/streams/ComplexUtilsTest.java
+++ /dev/null
@@ -1,772 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.numbers.complex.streams;
-
-import org.apache.commons.numbers.complex.Complex;
-
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-/**
- * Tests for {@link ComplexUtils}.
- */
-class ComplexUtilsTest {
-
- private static final double inf = Double.POSITIVE_INFINITY;
- private static final double negInf = Double.NEGATIVE_INFINITY;
- private static final double nan = Double.NaN;
- private static final double pi = Math.PI;
-
- private static final Complex negInfInf = Complex.ofCartesian(negInf, inf);
- private static final Complex infNegInf = Complex.ofCartesian(inf, negInf);
- private static final Complex infInf = Complex.ofCartesian(inf, inf);
- private static final Complex negInfNegInf = Complex.ofCartesian(negInf, negInf);
- private static final Complex infNaN = Complex.ofCartesian(inf, nan);
- private static final Complex NAN = Complex.ofCartesian(nan, nan);
-
- private static Complex[] c; // complex array with real values even and imag
- // values odd
- private static Complex[] cr; // complex array with real values consecutive
- private static Complex[] ci; // complex array with imag values consecutive
- private static double[] d; // real array with consecutive vals
- private static double[] di; // interleaved real array with consecutive vals,
- // 'interleaved' length
- private static float[] f; // real array with consecutive vals
- private static float[] fi; // interleaved real array with consecutive vals, interleaved
- // length
- private static double[] sr; // real component of split array, evens
- private static double[] si; // imag component of split array, odds
- private static float[] sfr; // real component of split array, float, evens
- private static float[] sfi; // imag component of split array, float, odds
- private static String msg; // error message for AssertEquals
- // CHECKSTYLE: stop MultipleVariableDeclarations
- private static Complex[][] c2d, cr2d, ci2d; // for 2d methods
- private static Complex[][][] c3d, cr3d, ci3d; // for 3d methods
- private static Complex[][][][] c4d, cr4d, ci4d; // for 3d methods
- private static double[][] di2d0, di2d1, sr2d, si2d;
- private static double[][][] di3d0, di3d1, di3d2, sr3d, si3d;
- private static double[][][][] di4d0, di4d1, di4d2, di4d3, sr4d, si4d;
- private static float[][] fi2d0, fi2d1, sfr2d, sfi2d;
- private static float[][][] fi3d0, fi3d1, fi3d2, sfr3d, sfi3d;
- private static float[][][][] sfr4d, sfi4d;
- // CHECKSTYLE: resume MultipleVariableDeclarations
-
- // CHECKSTYLE: stop MethodLength
- private static void setArrays() { // initial setup method
- c = new Complex[10];
- cr = new Complex[10];
- ci = new Complex[10];
- d = new double[10];
- f = new float[10];
- di = new double[20];
- fi = new float[20];
- sr = new double[10];
- si = new double[10];
- sfr = new float[10];
- sfi = new float[10];
- c2d = new Complex[10][10];
- cr2d = new Complex[10][10];
- ci2d = new Complex[10][10];
- c3d = new Complex[10][10][10];
- cr3d = new Complex[10][10][10];
- ci3d = new Complex[10][10][10];
- c4d = new Complex[10][10][10][10];
- cr4d = new Complex[10][10][10][10];
- ci4d = new Complex[10][10][10][10];
- sr2d = new double[10][10];
- sr3d = new double[10][10][10];
- sr4d = new double[10][10][10][10];
- si2d = new double[10][10];
- si3d = new double[10][10][10];
- si4d = new double[10][10][10][10];
- sfr2d = new float[10][10];
- sfr3d = new float[10][10][10];
- sfr4d = new float[10][10][10][10];
- sfi2d = new float[10][10];
- sfi3d = new float[10][10][10];
- sfi4d = new float[10][10][10][10];
- di2d0 = new double[20][10];
- di2d1 = new double[10][20];
- di3d0 = new double[20][10][10];
- di3d1 = new double[10][20][10];
- di3d2 = new double[10][10][20];
- di4d0 = new double[20][10][10][10];
- di4d1 = new double[10][20][10][10];
- di4d2 = new double[10][10][20][10];
- di4d3 = new double[10][10][10][20];
- fi2d0 = new float[20][10];
- fi2d1 = new float[10][20];
- fi3d0 = new float[20][10][10];
- fi3d1 = new float[10][20][10];
- fi3d2 = new float[10][10][20];
- for (int i = 0; i < 20; i += 2) {
- int halfI = i / 2;
-
- // Complex arrays
- c[halfI] = Complex.ofCartesian(i, i + 1);
- cr[halfI] = Complex.ofCartesian(halfI, 0);
- ci[halfI] = Complex.ofCartesian(0, halfI);
-
- // standalone - split equivalent to c
- sr[halfI] = i;
- si[halfI] = i + 1;
- sfr[halfI] = i;
- sfi[halfI] = i + 1;
-
- // depending on method used equivalents to cr or ci
- d[halfI] = halfI;
- f[halfI] = halfI;
-
- // interleaved - all equivalent to c2d
- di[i] = i;
- di[i + 1] = i + 1;
- fi[i] = i;
- fi[i + 1] = i + 1;
- }
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 20; j += 2) {
- int halfJ = j / 2;
- int real = 10 * i + j;
- int imaginary = 10 * i + j + 1;
-
- // Complex arrays
- c2d[i][halfJ] = Complex.ofCartesian(real, imaginary);
- cr2d[i][halfJ] = Complex.ofCartesian(real, 0);
- ci2d[i][halfJ] = Complex.ofCartesian(0, imaginary);
-
- // standalone - split equivalent to c2d, standalone equivalent to cr2d or ci2d
- sr2d[i][halfJ] = real;
- si2d[i][halfJ] = imaginary;
- sfr2d[i][halfJ] = real;
- sfi2d[i][halfJ] = imaginary;
-
- // interleaved - all equivalent to c2d
- di2d0[j][i] = 10 * halfJ + 2 * i;
- di2d0[j + 1][i] = di2d0[j][i] + 1;
- di2d1[i][j] = real;
- di2d1[i][j + 1] = imaginary;
- fi2d0[j][i] = 10 * halfJ + 2 * i;
- fi2d0[j + 1][i] = fi2d0[j][i] + 1;
- fi2d1[i][j] = real;
- fi2d1[i][j + 1] = imaginary;
- }
- }
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- for (int k = 0; k < 20; k += 2) {
- int halfK = k / 2;
- int real = 100 * i + 10 * j + k;
- int imaginary = 100 * i + 10 * j + k + 1;
-
- // Complex arrays
- c3d[i][j][halfK] = Complex.ofCartesian(real, imaginary);
- cr3d[i][j][halfK] = Complex.ofCartesian(real, 0);
- ci3d[i][j][halfK] = Complex.ofCartesian(0, imaginary);
-
- // standalone - split equivalent to c3d, standalone equivalent to cr3d or ci3d
- sr3d[i][j][halfK] = real;
- si3d[i][j][halfK] = imaginary;
- sfr3d[i][j][halfK] = real;
- sfi3d[i][j][halfK] = imaginary;
-
- // interleaved - all equivalent to c3d
- di3d0[k][i][j] = 100 * halfK + 10 * i + 2 * j;
- di3d0[k + 1][i][j] = di3d0[k][i][j] + 1;
- di3d1[j][k][i] = 100 * j + 10 * halfK + 2 * i;
- di3d1[j][k + 1][i] = di3d1[j][k][i] + 1;
- di3d2[i][j][k] = real;
- di3d2[i][j][k + 1] = imaginary;
- fi3d0[k][i][j] = 100 * halfK + 10 * i + 2 * j;
- fi3d0[k + 1][i][j] = fi3d0[k][i][j] + 1;
- fi3d1[j][k][i] = 100 * j + 10 * halfK + 2 * i;
- fi3d1[j][k + 1][i] = fi3d1[j][k][i] + 1;
- fi3d2[i][j][k] = real;
- fi3d2[i][j][k + 1] = imaginary;
- }
- }
- }
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- for (int k = 0; k < 10; k++) {
- for (int l = 0; l < 20; l += 2) {
- int halfL = l / 2;
- int real = 1000 * i + 100 * j + 10 * k + l;
- int imaginary = 1000 * i + 100 * j + 10 * k + l + 1;
-
- // Complex arrays
- c4d[i][j][k][halfL] = Complex.ofCartesian(real, imaginary);
- cr4d[i][j][k][halfL] = Complex.ofCartesian(real, 0);
- ci4d[i][j][k][halfL] = Complex.ofCartesian(0, imaginary);
-
- // standalone - split equivalent to c4d, standalone equivalent to cr4d or ci4d
- sr4d[i][j][k][halfL] = real;
- si4d[i][j][k][halfL] = imaginary;
- sfr4d[i][j][k][halfL] = real;
- sfi4d[i][j][k][halfL] = imaginary;
-
- // interleaved - all equivalent to c4d
- di4d0[l][i][j][k] = 1000 * halfL + 100 * i + 10 * j + 2 * k;
- di4d0[l + 1][i][j][k] = di4d0[l][i][j][k] + 1;
- di4d1[k][l][i][j] = 1000 * k + 100 * halfL + 10 * i + 2 * j;
- di4d1[k][l + 1][i][j] = di4d1[k][l][i][j] + 1;
- di4d2[j][k][l][i] = 1000 * j + 100 * k + 10 * halfL + 2 * i;
- di4d2[j][k][l + 1][i] = di4d2[j][k][l][i] + 1;
- di4d3[i][j][k][l] = real;
- di4d3[i][j][k][l + 1] = imaginary;
- }
- }
- }
- }
- msg = "";
- }
- // CHECKSTYLE: resume MethodLength
-
- @Test
- void testPolar2Complex() {
- TestUtils.assertEquals(Complex.ONE, ComplexUtils.polar2Complex(1, 0), 10e-12);
- TestUtils.assertEquals(Complex.ZERO, ComplexUtils.polar2Complex(0, 1), 10e-12);
- TestUtils.assertEquals(Complex.ZERO, ComplexUtils.polar2Complex(0, -1), 10e-12);
- TestUtils.assertEquals(Complex.I, ComplexUtils.polar2Complex(1, pi / 2), 10e-12);
- TestUtils.assertEquals(Complex.I.negate(), ComplexUtils.polar2Complex(1, -pi / 2), 10e-12);
- double r = 0;
- for (int i = 0; i < 5; i++) {
- r += i;
- double theta = 0;
- for (int j = 0; j < 20; j++) {
- theta += pi / 6;
- TestUtils.assertEquals(altPolar(r, theta), ComplexUtils.polar2Complex(r, theta), 10e-12);
- }
- theta = -2 * pi;
- for (int j = 0; j < 20; j++) {
- theta -= pi / 6;
- TestUtils.assertEquals(altPolar(r, theta), ComplexUtils.polar2Complex(r, theta), 10e-12);
- }
- }
- // 1D
- double[] r1D = new double[11];
- double[] theta1D = new double[11];
- for (int i = 0; i < 11; i++) {
- r1D[i] = i;
- }
- theta1D[5] = 0;
- for (int i = 1; i < 5; i++) {
- theta1D[5 + i] = theta1D[5 + i - 1] + pi / 6;
- theta1D[5 - i] = theta1D[5 + i + 1] - pi / 6;
- }
- Complex[] observed1D = ComplexUtils.polar2Complex(r1D, theta1D);
- Assertions.assertEquals(r1D.length, observed1D.length);
- for (int i = 0; i < r1D.length; i++) {
- Assertions.assertEquals(ComplexUtils.polar2Complex(r1D[i], theta1D[i]), observed1D[i]);
- }
-
- // 2D
- double[][] theta2D = new double[3][4];
- double[][] r2D = new double[3][4];
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 4; j++) {
- r2D[i][j] = i + j;
- theta2D[i][j] = i * j;
- }
- }
- Complex[][] observed2D = ComplexUtils.polar2Complex(r2D, theta2D);
- Assertions.assertEquals(r2D.length, observed2D.length);
- for (int i = 0; i < r2D.length; i++) {
- TestUtils.assertSame(msg, ComplexUtils.polar2Complex(r2D[i], theta2D[i]), observed2D[i]);
- }
-
- // 3D
- double[][][] theta3D = new double[3][4][3];
- double[][][] r3D = new double[3][4][3];
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 4; j++) {
- for (int k = 0; k < 3; k++) {
- r3D[i][j][k] = i + j + k;
- theta3D[i][j][k] = i * j * k;
- }
- }
- }
- Complex[][][] observed3D = ComplexUtils.polar2Complex(r3D, theta3D);
- Assertions.assertEquals(r3D.length, observed3D.length);
- for (int i = 0; i < r3D.length; i++) {
- TestUtils.assertSame(msg, ComplexUtils.polar2Complex(r3D[i], theta3D[i]), observed3D[i]);
- }
- }
-
- private Complex altPolar(double r, double theta) {
- return Complex.I.multiply(Complex.ofCartesian(theta, 0)).exp().multiply(Complex.ofCartesian(r, 0));
- }
-
- @Test
- void testPolar2ComplexIllegalModulus() {
- Assertions.assertThrows(IllegalArgumentException.class,
- () -> ComplexUtils.polar2Complex(-1, 0)
- );
- }
-
- @Test
- void testPolar2ComplexIllegalModulus1D() {
- Assertions.assertThrows(IllegalArgumentException.class,
- () -> ComplexUtils.polar2Complex(new double[]{0, -1, 2}, new double[]{0, 1, 2})
- );
- }
-
- @Test
- void testPolar2ComplexIllegalModulus2D() {
- Assertions.assertThrows(IllegalArgumentException.class,
- () -> ComplexUtils.polar2Complex(new double[][]{{0, 2, 2}, {0, -1, 2}}, new double[][]{{0, 1, 2}, {0, 1, 2}})
- );
- }
-
- @Test
- void testPolar2ComplexIllegalModulus3D() {
- Assertions.assertThrows(IllegalArgumentException.class,
- () -> ComplexUtils.polar2Complex(new double[][][]{{{0, 2, 2}}, {{0, -1, 2}}}, new double[][][]{{{0, 1, 2}}, {{0, 1, 2}}})
- );
- }
-
- @Test
- void testPolar2ComplexNaN() {
- TestUtils.assertSame(NAN, ComplexUtils.polar2Complex(nan, 1));
- TestUtils.assertSame(NAN, ComplexUtils.polar2Complex(1, nan));
- TestUtils.assertSame(NAN, ComplexUtils.polar2Complex(nan, nan));
- }
-
- @Test
- void testPolar2ComplexInf() {
- TestUtils.assertSame(NAN, ComplexUtils.polar2Complex(1, inf));
- TestUtils.assertSame(NAN, ComplexUtils.polar2Complex(1, negInf));
- TestUtils.assertSame(NAN, ComplexUtils.polar2Complex(inf, inf));
- TestUtils.assertSame(NAN, ComplexUtils.polar2Complex(inf, negInf));
- TestUtils.assertSame(infInf, ComplexUtils.polar2Complex(inf, pi / 4));
- TestUtils.assertSame(infNaN, ComplexUtils.polar2Complex(inf, 0));
- TestUtils.assertSame(infNegInf, ComplexUtils.polar2Complex(inf, -pi / 4));
- TestUtils.assertSame(negInfInf, ComplexUtils.polar2Complex(inf, 3 * pi / 4));
- TestUtils.assertSame(negInfNegInf, ComplexUtils.polar2Complex(inf, 5 * pi / 4));
- }
-
- @Test
- void testCExtract() {
- final double[] real = new double[] {negInf, -123.45, 0, 1, 234.56, pi, inf};
- final Complex[] complex = ComplexUtils.real2Complex(real);
-
- for (int i = 0; i < real.length; i++) {
- Assertions.assertEquals(real[i], complex[i].getReal());
- }
- }
-
- // EXTRACTION METHODS
-
- @Test
- void testExtractionMethods() {
- setArrays();
- // Extract complex from real double array, index 3
- TestUtils.assertSame(Complex.ofCartesian(3, 0), ComplexUtils.extractComplexFromRealArray(d, 3));
- // Extract complex from real float array, index 3
- TestUtils.assertSame(Complex.ofCartesian(3, 0), ComplexUtils.extractComplexFromRealArray(f, 3));
- // Extract complex from real double array, index 3
- TestUtils.assertSame(Complex.ofCartesian(0, 3), ComplexUtils.extractComplexFromImaginaryArray(d, 3));
- // Extract complex from real float array, index 3
- TestUtils.assertSame(Complex.ofCartesian(0, 3), ComplexUtils.extractComplexFromImaginaryArray(f, 3));
- // Extract real double from complex array, index 3
- Assertions.assertEquals(6, ComplexUtils.extractRealFromComplexArray(c, 3));
- // Extract real float from complex array, index 3
- Assertions.assertEquals(6, ComplexUtils.extractRealFloatFromComplexArray(c, 3));
- // Extract real double from complex array, index 3
- Assertions.assertEquals(7, ComplexUtils.extractImaginaryFromComplexArray(c, 3));
- // Extract real float from complex array, index 3
- Assertions.assertEquals(7, ComplexUtils.extractImaginaryFloatFromComplexArray(c, 3));
- // Extract complex from interleaved double array, index 3
- TestUtils.assertSame(Complex.ofCartesian(6, 7), ComplexUtils.extractComplexFromInterleavedArray(d, 3));
- // Extract interleaved double array from complex array, index 3
- Assertions.assertArrayEquals(new double[]{6d, 7d}, ComplexUtils.extractInterleavedFromComplexArray(c, 3));
- // Extract interleaved float array from complex array, index 3
- Assertions.assertArrayEquals(new float[]{6f, 7f}, ComplexUtils.extractInterleavedFloatFromComplexArray(c, 3));
- // Extract complex from interleaved float array, index 3
- TestUtils.assertSame(Complex.ofCartesian(6, 7), ComplexUtils.extractComplexFromInterleavedArray(f, 3));
- // Extract interleaved double from complex array, index 3
- Assertions.assertArrayEquals(new double[] {6, 7}, ComplexUtils.extractInterleavedFromComplexArray(c, 3),
- Math.ulp(1), msg);
- // Extract interleaved float from complex array, index 3
- Assertions.assertArrayEquals(new double[] {6, 7}, ComplexUtils.extractInterleavedFromComplexArray(c, 3),
- Math.ulp(1), msg);
- }
- // REAL <-> COMPLEX
-
- @Test
- void testRealToComplex() {
- setArrays();
- // Real double to complex, whole array
- TestUtils.assertEquals(msg, cr, ComplexUtils.real2Complex(d), Math.ulp(1.0));
- // Real float to complex, whole array
- TestUtils.assertEquals(msg, cr, ComplexUtils.real2Complex(f), Math.ulp(1.0));
-
- // 2d
- TestUtils.assertEquals(msg, cr2d, ComplexUtils.real2Complex(sr2d), 0);
- TestUtils.assertEquals(msg, cr2d, ComplexUtils.real2Complex(sfr2d), 0);
-
- // 3d
- TestUtils.assertEquals(msg, cr3d, ComplexUtils.real2Complex(sr3d), 0);
- TestUtils.assertEquals(msg, cr3d, ComplexUtils.real2Complex(sfr3d), 0);
-
- // 4d
- TestUtils.assertEquals(msg, cr4d, ComplexUtils.real2Complex(sr4d), 0);
- }
-
- @Test
- void testComplexToReal() {
- setArrays();
- // Real complex to double, whole array
- Assertions.assertArrayEquals(sr, ComplexUtils.complex2Real(c), Math.ulp(1.0), msg);
- // Real complex to float, whole array
- Assertions.assertArrayEquals(sfr, ComplexUtils.complex2RealFloat(c), Math.ulp(1.0f), msg);
-
- // 2d
- TestUtils.assertEquals(msg, sr2d, ComplexUtils.complex2Real(cr2d), 0);
- TestUtils.assertEquals(msg, sfr2d, ComplexUtils.complex2RealFloat(cr2d), 0);
-
- // 3d
- TestUtils.assertEquals(msg, sr3d, ComplexUtils.complex2Real(cr3d), 0);
- TestUtils.assertEquals(msg, sfr3d, ComplexUtils.complex2RealFloat(cr3d), 0);
-
- // 4d
- TestUtils.assertEquals(msg, sr4d, ComplexUtils.complex2Real(cr4d), 0);
- TestUtils.assertEquals(msg, sfr4d, ComplexUtils.complex2RealFloat(cr4d), 0);
- }
-
- // IMAGINARY <-> COMPLEX
-
- @Test
- void testImaginaryToComplex() {
- setArrays();
- // Imaginary double to complex, whole array
- TestUtils.assertEquals(msg, ci, ComplexUtils.imaginary2Complex(d), Math.ulp(1.0));
- // Imaginary float to complex, whole array
- TestUtils.assertEquals(msg, ci, ComplexUtils.imaginary2Complex(f), Math.ulp(1.0));
-
- // 2d
- TestUtils.assertEquals(msg, ci2d, ComplexUtils.imaginary2Complex(si2d), 0);
-
- // 3d
- TestUtils.assertEquals(msg, ci3d, ComplexUtils.imaginary2Complex(si3d), 0);
-
- // 4d
- TestUtils.assertEquals(msg, ci4d, ComplexUtils.imaginary2Complex(si4d), 0);
- }
-
- @Test
- void testComplexToImaginary() {
- setArrays();
- // Imaginary complex to double, whole array
- Assertions.assertArrayEquals(si, ComplexUtils.complex2Imaginary(c), Math.ulp(1.0), msg);
- // Imaginary complex to float, whole array
- Assertions.assertArrayEquals(sfi, ComplexUtils.complex2ImaginaryFloat(c), Math.ulp(1.0f), msg);
-
- // 2d
- TestUtils.assertEquals(msg, si2d, ComplexUtils.complex2Imaginary(ci2d), 0);
- TestUtils.assertEquals(msg, sfi2d, ComplexUtils.complex2ImaginaryFloat(ci2d), 0);
-
- // 3d
- TestUtils.assertEquals(msg, si3d, ComplexUtils.complex2Imaginary(ci3d), 0);
- TestUtils.assertEquals(msg, sfi3d, ComplexUtils.complex2ImaginaryFloat(ci3d), 0);
-
- // 4d
- TestUtils.assertEquals(msg, si4d, ComplexUtils.complex2Imaginary(ci4d), 0);
- TestUtils.assertEquals(msg, sfi4d, ComplexUtils.complex2ImaginaryFloat(ci4d), 0);
- }
-
- // INTERLEAVED <-> COMPLEX
-
- @Test
- void testComplex2InterleavedIllegalIndex2Dmin() {
- Assertions.assertThrows(IllegalArgumentException.class,
- () -> ComplexUtils.complex2Interleaved(c2d, -1)
- );
- }
-
- @Test
- void testComplex2InterleavedIllegalIndex2Dmax() {
- Assertions.assertThrows(IllegalArgumentException.class,
- () -> ComplexUtils.complex2Interleaved(c2d, 2)
- );
- }
-
- @Test
- void testComplex2InterleavedIllegalIndex3Dmin() {
- Assertions.assertThrows(IllegalArgumentException.class,
- () -> ComplexUtils.complex2Interleaved(c3d, -1)
- );
- }
-
- @Test
- void testComplex2InterleavedIllegalIndex3Dmax() {
- Assertions.assertThrows(IllegalArgumentException.class,
- () -> ComplexUtils.complex2Interleaved(c3d, 3)
- );
- }
-
- @Test
- void testComplex2InterleavedIllegalIndex4Dmin() {
- Assertions.assertThrows(IllegalArgumentException.class,
- () -> ComplexUtils.complex2Interleaved(c4d, -1)
- );
- }
-
- @Test
- void testComplex2InterleavedIllegalIndex4Dmax() {
- Assertions.assertThrows(IllegalArgumentException.class,
- () -> ComplexUtils.complex2Interleaved(c4d, 4)
- );
- }
-
- @Test
- void testComplex2InterleavedFloatIllegalIndex2Dmin() {
- Assertions.assertThrows(IllegalArgumentException.class,
- () -> ComplexUtils.complex2InterleavedFloat(c2d, -1)
- );
- }
-
- @Test
- void testComplex2InterleavedFloatIllegalIndex2Dmax() {
- Assertions.assertThrows(IllegalArgumentException.class,
- () -> ComplexUtils.complex2InterleavedFloat(c2d, 2)
- );
- }
-
- @Test
- void testComplex2InterleavedFloatIllegalIndex3Dmin() {
- Assertions.assertThrows(IllegalArgumentException.class,
- () -> ComplexUtils.complex2InterleavedFloat(c3d, -1)
- );
- }
-
- @Test
- void testComplex2InterleavedFloatIllegalIndex3Dmax() {
- Assertions.assertThrows(IllegalArgumentException.class,
- () -> ComplexUtils.complex2InterleavedFloat(c3d, 3)
- );
- }
-
- @Test
- void testInterleaved2ComplexIllegalIndex2Dmin() {
- Assertions.assertThrows(IllegalArgumentException.class,
- () -> ComplexUtils.interleaved2Complex(di2d0, -1)
- );
- }
-
- @Test
- void testInterleaved2ComplexIllegalIndex2Dmax() {
- Assertions.assertThrows(IllegalArgumentException.class,
- () -> ComplexUtils.interleaved2Complex(di2d0, 2)
- );
- }
-
- @Test
- void testInterleaved2ComplexIllegalIndex3Dmin() {
- Assertions.assertThrows(IllegalArgumentException.class,
- () -> ComplexUtils.interleaved2Complex(di3d0, -1)
- );
- }
-
- @Test
- void testInterleaved2ComplexIllegalIndex3Dmax() {
- Assertions.assertThrows(IllegalArgumentException.class,
- () -> ComplexUtils.interleaved2Complex(di3d0, 3)
- );
- }
-
- @Test
- void testInterleaved2ComplexIllegalIndex4Dmin() {
- Assertions.assertThrows(IllegalArgumentException.class,
- () -> ComplexUtils.interleaved2Complex(di4d0, -1)
- );
- }
-
- @Test
- void testInterleaved2ComplexIllegalIndex4Dmax() {
- Assertions.assertThrows(IllegalArgumentException.class,
- () -> ComplexUtils.interleaved2Complex(di4d0, 4)
- );
- }
-
- @Test
- void testInterleaved2ComplexFloatIllegalIndex2Dmin() {
- Assertions.assertThrows(IllegalArgumentException.class,
- () -> ComplexUtils.interleaved2Complex(fi2d0, -1)
- );
- }
-
- @Test
- void testInterleaved2ComplexFloatIllegalIndex2Dmax() {
- Assertions.assertThrows(IllegalArgumentException.class,
- () -> ComplexUtils.interleaved2Complex(fi2d0, 2)
- );
- }
-
- @Test
- void testInterleaved2ComplexFloatIllegalIndex3Dmin() {
- Assertions.assertThrows(IllegalArgumentException.class,
- () -> ComplexUtils.interleaved2Complex(fi3d0, -1)
- );
- }
-
- @Test
- void testInterleaved2ComplexFloatIllegalIndex3Dmax() {
- Assertions.assertThrows(IllegalArgumentException.class,
- () -> ComplexUtils.interleaved2Complex(fi3d0, 3)
- );
- }
-
- @Test
- void testInterleavedToComplex() {
- setArrays();
- // Interleaved double to complex, whole array
- TestUtils.assertEquals(msg, c, ComplexUtils.interleaved2Complex(di), Math.ulp(1.0));
- // Interleaved float to complex, whole array
- TestUtils.assertEquals(msg, c, ComplexUtils.interleaved2Complex(fi), Math.ulp(1.0));
-
- // 2d
- TestUtils.assertSame(msg, c2d, ComplexUtils.interleaved2Complex(di2d0, 0));
- TestUtils.assertSame(msg, c2d, ComplexUtils.interleaved2Complex(di2d1, 1));
- TestUtils.assertSame(msg, c2d, ComplexUtils.interleaved2Complex(di2d1));
-
- TestUtils.assertSame(msg, c2d, ComplexUtils.interleaved2Complex(fi2d0, 0));
- TestUtils.assertSame(msg, c2d, ComplexUtils.interleaved2Complex(fi2d1, 1));
- TestUtils.assertSame(msg, c2d, ComplexUtils.interleaved2Complex(fi2d1));
-
- // 3d
- TestUtils.assertSame(msg, c3d, ComplexUtils.interleaved2Complex(di3d0, 0));
- TestUtils.assertSame(msg, c3d, ComplexUtils.interleaved2Complex(di3d1, 1));
- TestUtils.assertSame(msg, c3d, ComplexUtils.interleaved2Complex(di3d2, 2));
- TestUtils.assertSame(msg, c3d, ComplexUtils.interleaved2Complex(di3d2));
-
- TestUtils.assertSame(msg, c3d, ComplexUtils.interleaved2Complex(fi3d0, 0));
- TestUtils.assertSame(msg, c3d, ComplexUtils.interleaved2Complex(fi3d1, 1));
- TestUtils.assertSame(msg, c3d, ComplexUtils.interleaved2Complex(fi3d2, 2));
- TestUtils.assertSame(msg, c3d, ComplexUtils.interleaved2Complex(fi3d2));
-
- // 4d
- TestUtils.assertSame(msg, c4d, ComplexUtils.interleaved2Complex(di4d0, 0));
- TestUtils.assertSame(msg, c4d, ComplexUtils.interleaved2Complex(di4d1, 1));
- TestUtils.assertSame(msg, c4d, ComplexUtils.interleaved2Complex(di4d2, 2));
- TestUtils.assertSame(msg, c4d, ComplexUtils.interleaved2Complex(di4d3, 3));
- }
-
- @Test
- void testComplexToInterleaved() {
- setArrays();
- Assertions.assertArrayEquals(di, ComplexUtils.complex2Interleaved(c), Math.ulp(1.0), msg);
- // Interleaved complex to float, whole array
- Assertions.assertArrayEquals(fi, ComplexUtils.complex2InterleavedFloat(c), Math.ulp(1.0f), msg);
-
- // 2d
- TestUtils.assertEquals(msg, di2d0, ComplexUtils.complex2Interleaved(c2d, 0), 0);
- TestUtils.assertEquals(msg, di2d1, ComplexUtils.complex2Interleaved(c2d, 1), 0);
- TestUtils.assertEquals(msg, di2d1, ComplexUtils.complex2Interleaved(c2d), 0);
-
- TestUtils.assertEquals(msg, fi2d0, ComplexUtils.complex2InterleavedFloat(c2d, 0), 0);
- TestUtils.assertEquals(msg, fi2d1, ComplexUtils.complex2InterleavedFloat(c2d, 1), 0);
- TestUtils.assertEquals(msg, fi2d1, ComplexUtils.complex2InterleavedFloat(c2d), 0);
-
- // 3d
- TestUtils.assertEquals(msg, di3d0, ComplexUtils.complex2Interleaved(c3d, 0), 0);
- TestUtils.assertEquals(msg, di3d1, ComplexUtils.complex2Interleaved(c3d, 1), 0);
- TestUtils.assertEquals(msg, di3d2, ComplexUtils.complex2Interleaved(c3d, 2), 0);
- TestUtils.assertEquals(msg, di3d2, ComplexUtils.complex2Interleaved(c3d), 0);
-
- TestUtils.assertEquals(msg, fi3d0, ComplexUtils.complex2InterleavedFloat(c3d, 0), 0);
- TestUtils.assertEquals(msg, fi3d1, ComplexUtils.complex2InterleavedFloat(c3d, 1), 0);
- TestUtils.assertEquals(msg, fi3d2, ComplexUtils.complex2InterleavedFloat(c3d, 2), 0);
- TestUtils.assertEquals(msg, fi3d2, ComplexUtils.complex2InterleavedFloat(c3d), 0);
-
- // 4d
- TestUtils.assertEquals(msg, di4d0, ComplexUtils.complex2Interleaved(c4d, 0), 0);
- TestUtils.assertEquals(msg, di4d1, ComplexUtils.complex2Interleaved(c4d, 1), 0);
- TestUtils.assertEquals(msg, di4d2, ComplexUtils.complex2Interleaved(c4d, 2), 0);
- TestUtils.assertEquals(msg, di4d3, ComplexUtils.complex2Interleaved(c4d, 3), 0);
- TestUtils.assertEquals(msg, di4d3, ComplexUtils.complex2Interleaved(c4d), 0);
- }
-
- // SPLIT TO COMPLEX
- @Test
- void testSplit2Complex() {
- setArrays();
- // Split double to complex, whole array
- TestUtils.assertEquals(msg, c, ComplexUtils.split2Complex(sr, si), Math.ulp(1.0));
-
- TestUtils.assertSame(msg, c2d, ComplexUtils.split2Complex(sr2d, si2d));
- TestUtils.assertSame(msg, c3d, ComplexUtils.split2Complex(sr3d, si3d));
- TestUtils.assertSame(msg, c4d, ComplexUtils.split2Complex(sr4d, si4d));
- TestUtils.assertSame(msg, c2d, ComplexUtils.split2Complex(sfr2d, sfi2d));
- TestUtils.assertSame(msg, c3d, ComplexUtils.split2Complex(sfr3d, sfi3d));
- }
-
- // INITIALIZATION METHODS
-
- @Test
- void testInitialize() {
- Complex[] complexes = new Complex[10];
- ComplexUtils.initialize(complexes);
- for (Complex cc : complexes) {
- TestUtils.assertEquals(Complex.ofCartesian(0, 0), cc, Math.ulp(0));
- }
- }
-
- @Test
- void testInitialize2d() {
- Complex[][] complexes = new Complex[10][10];
- ComplexUtils.initialize(complexes);
- for (Complex[] c1 : complexes) {
- for (Complex c0 : c1) {
- TestUtils.assertEquals(Complex.ofCartesian(0, 0), c0, Math.ulp(0));
- }
- }
- }
-
- @Test
- void testInitialize3d() {
- Complex[][][] complexes = new Complex[10][10][10];
- ComplexUtils.initialize(complexes);
- for (Complex[][] c2 : complexes) {
- for (Complex[] c1 : c2) {
- for (Complex c0 : c1) {
- TestUtils.assertEquals(Complex.ofCartesian(0, 0), c0, Math.ulp(0));
- }
- }
- }
- }
-
- @Test
- void testAbs() {
- setArrays();
- double[] observed = ComplexUtils.abs(c);
- Assertions.assertEquals(c.length, observed.length);
- for (int i = 0; i < c.length; i++) {
- Assertions.assertEquals(c[i].abs(), observed[i]);
- }
- }
-
- @Test
- void testArg() {
- setArrays();
- double[] observed = ComplexUtils.arg(c);
- Assertions.assertEquals(c.length, observed.length);
- for (int i = 0; i < c.length; i++) {
- Assertions.assertEquals(c[i].arg(), observed[i]);
- }
- }
-}
diff --git a/commons-numbers-complex-streams/src/test/java/org/apache/commons/numbers/complex/streams/TestUtils.java b/commons-numbers-complex-streams/src/test/java/org/apache/commons/numbers/complex/streams/TestUtils.java
deleted file mode 100644
index 0b3ff66..0000000
--- a/commons-numbers-complex-streams/src/test/java/org/apache/commons/numbers/complex/streams/TestUtils.java
+++ /dev/null
@@ -1,210 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.numbers.complex.streams;
-
-import org.apache.commons.numbers.complex.Complex;
-import org.apache.commons.numbers.core.Precision;
-
-import org.junit.jupiter.api.Assertions;
-
-/**
- * Test utilities.
- */
-@SuppressWarnings("WeakerAccess")
-final class TestUtils {
- /**
- * Collection of static methods used in math unit tests.
- */
- private TestUtils() {
- super();
- }
-
- /**
- * Verifies that the two arguments are exactly the same, either
- * both NaN or infinities of same sign, or identical floating point values.
- */
- public static void assertSame(String msg, Complex[] expected, Complex[] actual) {
- assertEquals(msg, expected, actual, 0);
- }
-
- /**
- * Verifies that the two arguments are exactly the same, either
- * both NaN or infinities of same sign, or identical floating point values.
- */
- public static void assertSame(String msg, Complex[][] expected, Complex[][] actual) {
- assertEquals(msg, expected, actual, 0);
- }
-
- /**
- * Verifies that the two arguments are exactly the same, either
- * both NaN or infinities of same sign, or identical floating point values.
- */
- public static void assertSame(String msg, Complex[][][] expected, Complex[][][] actual) {
- assertEquals(msg, expected, actual, 0);
- }
-
- /**
- * Verifies that the two arguments are exactly the same, either
- * both NaN or infinities of same sign, or identical floating point values.
- */
- public static void assertSame(String msg, Complex[][][][] expected, Complex[][][][] actual) {
- assertEquals(msg, expected, actual, 0);
- }
-
- /**
- * Verifies that real and imaginary parts of the two complex arguments
- * are exactly the same. Also ensures that NaN / infinite components match.
- */
- public static void assertSame(Complex expected, Complex actual) {
- Assertions.assertEquals(expected.getReal(), actual.getReal());
- Assertions.assertEquals(expected.getImaginary(), actual.getImaginary());
- }
-
- /**
- * Verifies that real and imaginary parts of the two complex arguments
- * differ by at most delta. Also ensures that NaN / infinite components match.
- */
- public static void assertEquals(Complex expected, Complex actual, double delta) {
- Assertions.assertEquals(expected.getReal(), actual.getReal(), delta, "Real Values Differ");
- Assertions.assertEquals(expected.getImaginary(), actual.getImaginary(), delta, "Imaginary Values Differ");
- }
-
- /** verifies that two 2D arrays are close (sup norm) */
- public static void assertEquals(String msg, double[][] expected, double[][] observed, double tolerance) {
- assertArrayLengthsEqual(msg, expected.length, observed.length);
- for (int i = 0; i < expected.length; i++) {
- Assertions.assertArrayEquals(expected[i], observed[i], tolerance, msg + "[" + i + "]");
- }
- }
-
- /** verifies that two 3D arrays are close (sup norm) */
- public static void assertEquals(String msg, double[][][] expected, double[][][] observed, double tolerance) {
- assertArrayLengthsEqual(msg, expected.length, observed.length);
- for (int i = 0; i < expected.length; i++) {
- assertEquals(msg + "[" + i + "]", expected[i], observed[i], tolerance);
- }
- }
-
- /** verifies that two 4D arrays are close (sup norm) */
- public static void assertEquals(String msg, double[][][][] expected, double[][][][] observed, double tolerance) {
- assertArrayLengthsEqual(msg, expected.length, observed.length);
- for (int i = 0; i < expected.length; i++) {
- assertEquals(msg + "[" + i + "]", expected[i], observed[i], tolerance);
- }
- }
-
- /** verifies that two 4D arrays are close (sup norm) */
- public static void assertEquals(String msg, float[][][][] expected, float[][][][] observed, float tolerance) {
- assertArrayLengthsEqual(msg, expected.length, observed.length);
- for (int i = 0; i < expected.length; i++) {
- assertEquals(msg + "[" + i + "]", expected[i], observed[i], tolerance);
- }
- }
-
- /** verifies that two 2D arrays are close (sup norm) */
- public static void assertEquals(String msg, float[][] expected, float[][] observed, float tolerance) {
- assertArrayLengthsEqual(msg, expected.length, observed.length);
- for (int i = 0; i < expected.length; i++) {
- Assertions.assertArrayEquals(expected[i], observed[i], tolerance, msg + "[" + i + "]");
- }
- }
-
- /** verifies that two 3D arrays are close (sup norm) */
- public static void assertEquals(String msg, float[][][] expected, float[][][] observed, float tolerance) {
- assertArrayLengthsEqual(msg, expected.length, observed.length);
- for (int i = 0; i < expected.length; i++) {
- assertEquals(msg + "[" + i + "]", expected[i], observed[i], tolerance);
- }
- }
-
- /** verifies that two arrays are close (sup norm) */
- public static void assertEquals(String msg, Complex[] expected, Complex[] observed, double tolerance) {
- assertArrayLengthsEqual(msg, expected.length, observed.length);
- StringBuilder out = new StringBuilder(msg);
- boolean failure = false;
- for (int i = 0; i < expected.length; i++) {
- if (!Precision.equalsIncludingNaN(expected[i].getReal(), observed[i].getReal(), tolerance)) {
- failure = true;
- out.append("\n[").append(i).append("] ");
- out.append("Real elements differ. ");
- out.append(" expected = ");
- out.append(expected[i].getReal());
- out.append(" observed = ");
- out.append(observed[i].getReal());
- }
- if (!Precision.equalsIncludingNaN(expected[i].getImaginary(), observed[i].getImaginary(), tolerance)) {
- failure = true;
- out.append("\n[").append(i).append("] ");
- out.append("Imaginary elements differ. ");
- out.append(" expected = ");
- out.append(expected[i].getImaginary());
- out.append(" observed = ");
- out.append(observed[i].getImaginary());
- }
- }
- if (failure) {
- Assertions.fail(out.toString());
- }
- }
-
- /** verifies that two 2D arrays are close (sup norm) */
- public static void assertEquals(String msg, Complex[][] expected, Complex[][] observed, double tolerance) {
- assertArrayLengthsEqual(msg, expected.length, observed.length);
- for (int i = 0; i < expected.length; i++) {
- assertEquals(msg + "[" + i + "]", expected[i], observed[i], tolerance);
- }
- }
-
- /** verifies that two 3D arrays are close (sup norm) */
- public static void assertEquals(String msg, Complex[][][] expected, Complex[][][] observed, double tolerance) {
- assertArrayLengthsEqual(msg, expected.length, observed.length);
- for (int i = 0; i < expected.length; i++) {
- assertEquals(msg + "[" + i + "]", expected[i], observed[i], tolerance);
- }
- }
-
- /** verifies that two 4D arrays are close (sup norm) */
- public static void assertEquals(String msg, Complex[][][][] expected, Complex[][][][] observed, double tolerance) {
- assertArrayLengthsEqual(msg, expected.length, observed.length);
- for (int i = 0; i < expected.length; i++) {
- assertEquals(msg + "[" + i + "]", expected[i], observed[i], tolerance);
- }
- }
-
- /**
- * Assert that the given array lengths are the same
- * @param msg Initial message
- * @param expectedLength expected array length
- * @param observedLength observed array length
- */
- private static void assertArrayLengthsEqual(String msg, int expectedLength, int observedLength) {
- if (expectedLength != observedLength) {
- StringBuilder out = new StringBuilder(msg);
- if (msg != null && msg.length() > 0) {
- out.append("\n");
- }
- out.append("Arrays not same length. \n");
- out.append("expected has length ").append(expectedLength);
- out.append(" observed has length = ").append(observedLength);
- Assertions.fail(out.toString());
- }
-
- }
-}
-
-