001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.math4.transform;
018
019import java.util.function.DoubleUnaryOperator;
020import java.util.function.UnaryOperator;
021
022import org.apache.commons.numbers.complex.Complex;
023
024/**
025 * {@link Complex} transform.
026 * <p>
027 * Such transforms include {@link FastSineTransform sine transform},
028 * {@link FastCosineTransform cosine transform} or {@link
029 * FastHadamardTransform Hadamard transform}.
030 */
031public interface ComplexTransform extends UnaryOperator<Complex[]> {
032    /**
033     * Returns the transform of the specified data set.
034     *
035     * @param f the data array to be transformed (signal).
036     * @return the transformed array (spectrum).
037     * @throws IllegalArgumentException if the transform cannot be performed.
038     */
039    Complex[] apply(Complex[] f);
040
041    /**
042     * Returns the transform of the specified data set.
043     *
044     * @param f the data array to be transformed (signal).
045     * @return the transformed array (spectrum).
046     * @throws IllegalArgumentException if the transform cannot be performed.
047     */
048    Complex[] apply(double[] f);
049
050    /**
051     * Returns the transform of the specified function.
052     *
053     * @param f Function to be sampled and transformed.
054     * @param min Lower bound (inclusive) of the interval.
055     * @param max Upper bound (exclusive) of the interval.
056     * @param n Number of sample points.
057     * @return the result.
058     * @throws IllegalArgumentException if the transform cannot be performed.
059     */
060    default Complex[] apply(DoubleUnaryOperator f,
061                            double min,
062                            double max,
063                            int n) {
064        return apply(TransformUtils.sample(f, min, max, n));
065    }
066}