Java Matrix Multiply multiply(float[][] a, float num)

Here you can find the source of multiply(float[][] a, float num)

Description

Computes the pointwise multiplication of an array by num , leaving the result in a .

License

Apache License

Parameter

Parameter Description
a array
num number

Declaration

public static void multiply(float[][] a, float num) 

Method Source Code

//package com.java2s;
/*/* w w  w  .j  ava2  s  . c o  m*/
 * Copyright 2016 Universidad Nacional de Colombia
 * 
 * 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.
 */

public class Main {
    /**
     * Computes the pointwise multiplication of an array by {@code num}, leaving
     * the result in {@code a}.
     *
     * @param a array
     * @param num number
     *
     * @since JDiffraction 1.2
     */
    public static void multiply(float[][] a, float num) {
        checkDimension(a);
        int M = a.length;
        int N = a[0].length;

        for (int i = 0; i < M; i++) {
            for (int j = 0; j < N; j++) {
                a[i][j] = a[i][j] * num;
            }
        }
    }

    /**
     * Computes the pointwise multiplication of an array by {@code num}, leaving
     * the result in {@code a}.
     *
     * @param a array
     * @param num number
     *
     * @since JDiffraction 1.2
     */
    public static void multiply(double[][] a, double num) {
        checkDimension(a);
        int M = a.length;
        int N = a[0].length;

        for (int i = 0; i < M; i++) {
            for (int j = 0; j < N; j++) {
                a[i][j] = a[i][j] * num;
            }
        }
    }

    private static void checkDimension(float[][] a) {
        if (a.length == 0) {
            throw new IllegalArgumentException("Arrays dimension must be greater than 0.");
        } else if (a[0].length == 0) {
            throw new IllegalArgumentException("Arrays dimension must be greater than 0.");
        }
    }

    private static void checkDimension(double[][] a) {
        if (a.length == 0) {
            throw new IllegalArgumentException("Arrays dimension must be greater than 0.");
        } else if (a[0].length == 0) {
            throw new IllegalArgumentException("Arrays dimension must be greater than 0.");
        }
    }
}

Related

  1. multiply(double[][] m, double[] x)
  2. multiply(double[][] m1, double[][] m2)
  3. multiply(double[][] p, double[][] q)
  4. multiply(double[][] x, double[][] y)
  5. multiply(final double[][] A, final double[][] B)
  6. multiply(float[][] a, float[][] b)
  7. multiply(int[][] mat1, int[][] mat2)
  8. multiply(String[] tempResult, int nextIndex, String[][] pys)
  9. multiplyAffine(final double[][] A, final double[][] B, final double[][] dest, int n)