1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.commons.numbers.examples.jmh.core; 18 19 /** 20 * Computes linear combinations as the the sum of the products of two sequences of numbers 21 * <code>a<sub>i</sub> b<sub>i</sub></code>. 22 * 23 * @see <a href="https://en.wikipedia.org/wiki/Dot_product">Dot product</a> 24 */ 25 public interface LinearCombination { 26 /** 27 * Compute the sum of the products of two sequences of 2 factors. 28 */ 29 @FunctionalInterface 30 interface TwoD { 31 /** 32 * Compute the sum of the products of two sequences of factors. 33 * 34 * @param a1 First factor of the first term. 35 * @param b1 Second factor of the first term. 36 * @param a2 First factor of the second term. 37 * @param b2 Second factor of the second term. 38 * @return \( a_1 b_1 + a_2 b_2 \) 39 */ 40 double value(double a1, double b1, double a2, double b2); 41 } 42 43 /** 44 * Compute the sum of the products of two sequences of 3 factors. 45 */ 46 @FunctionalInterface 47 interface ThreeD { 48 /** 49 * Compute the sum of the products of two sequences of factors. 50 * 51 * @param a1 First factor of the first term. 52 * @param b1 Second factor of the first term. 53 * @param a2 First factor of the second term. 54 * @param b2 Second factor of the second term. 55 * @param a3 First factor of the third term. 56 * @param b3 Second factor of the third term. 57 * @return \( a_1 b_1 + a_2 b_2 + a_3 b_3 \) 58 */ 59 double value(double a1, double b1, double a2, double b2, double a3, double b3); 60 } 61 62 /** 63 * Compute the sum of the products of two sequences of 4 factors. 64 */ 65 @FunctionalInterface 66 interface FourD { 67 /** 68 * Compute the sum of the products of two sequences of factors. 69 * 70 * @param a1 First factor of the first term. 71 * @param b1 Second factor of the first term. 72 * @param a2 First factor of the second term. 73 * @param b2 Second factor of the second term. 74 * @param a3 First factor of the third term. 75 * @param b3 Second factor of the third term. 76 * @param a4 First factor of the fourth term. 77 * @param b4 Second factor of the fourth term. 78 * @return \( a_1 b_1 + a_2 b_2 + a_3 b_3 + a_4 b_4 \) 79 */ 80 double value(double a1, double b1, double a2, double b2, double a3, double b3, double a4, double b4); 81 } 82 83 /** 84 * Compute the sum of the products of two sequences of {@code n} factors. 85 */ 86 @FunctionalInterface 87 interface ND { 88 /** 89 * Compute the sum of the products of two sequences of factors. 90 * 91 * @param a Factors. 92 * @param b Factors. 93 * @return \( \sum_i a_i b_i \). 94 * @throws IllegalArgumentException if the sizes of the arrays are different. 95 */ 96 double value(double[] a, double[] b); 97 } 98 }