IntervalMatrixFactory.java

/**
 * Copyright (C) 2021 MKLab.org (Koga Laboratory)
 *
 * 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.
 */
package org.mklab.cga.interval.matrix;

import org.mklab.cga.interval.scalar.IntervalComplexNumericalScalar;
import org.mklab.cga.interval.scalar.IntervalRealNumericalScalar;
import org.mklab.nfc.matrix.ComplexNumericalMatrix;
import org.mklab.nfc.matrix.RealNumericalMatrix;
import org.mklab.nfc.scalar.ComplexNumericalScalar;
import org.mklab.nfc.scalar.RealNumericalScalar;


/**
 * @author koga
 * @version $Revision$, 2021/10/07
 */
public class IntervalMatrixFactory {

  /**
   * Creates {@link IntervalMatrixFactory}.
   */
  private IntervalMatrixFactory() {
    // nothing to do
  }

  /**
   * Creates interval matrix.
   * 
   * @param rs RS
   * @param ris RIS
   * @return RIM
   * @param <RIS> 実区間スカラーの型
   * @param <RIM> 実区間行列の型
   * @param <CIS> 複素区間スカラーの型
   * @param <CIM> 複素区間行列の型
   * @param <RS> 実スカラーの型
   * @param <RM> 実行列の型
   * @param <CS> 複素スカラーの型
   * @param <CM> 複素行列の型
   */
  public static <RIS extends IntervalRealNumericalScalar<RIS, RIM, CIS, CIM, RS, RM, CS, CM>, RIM extends IntervalRealNumericalMatrix<RIS, RIM, CIS, CIM, RS, RM, CS, CM>, CIS extends IntervalComplexNumericalScalar<RIS, RIM, CIS, CIM, RS, RM, CS, CM>, CIM extends IntervalComplexNumericalMatrix<RIS, RIM, CIS, CIM, RS, RM, CS, CM>, RS extends RealNumericalScalar<RS, RM, CS, CM>, RM extends RealNumericalMatrix<RS, RM, CS, CM>, CS extends ComplexNumericalScalar<RS, RM, CS, CM>, CM extends ComplexNumericalMatrix<RS, RM, CS, CM>> RIM create(
      RS[][] rs, RIS ris) {
    int rowSize = rs.length;
    int columnSize = rs[0].length;
    RIS[][] riss = ris.createArray(rowSize, columnSize);
    for (int i = 0; i < rowSize; i++) {
      for (int j = 0; j < columnSize; j++) {
        riss[i][j] = ris.create(rs[i][j]);
      }
    }

    return ris.createGrid(riss);
  }

  /**
   * Creates interval matrix.
   * 
   * @param rs RS
   * @param ris RIS
   * @return RIM
   * @param <RIS> 実区間スカラーの型
   * @param <RIM> 実区間行列の型
   * @param <CIS> 複素区間スカラーの型
   * @param <CIM> 複素区間行列の型
   * @param <RS> 実スカラーの型
   * @param <RM> 実行列の型
   * @param <CS> 複素スカラーの型
   * @param <CM> 複素行列の型
   */
  public static <RIS extends IntervalRealNumericalScalar<RIS, RIM, CIS, CIM, RS, RM, CS, CM>, RIM extends IntervalRealNumericalMatrix<RIS, RIM, CIS, CIM, RS, RM, CS, CM>, CIS extends IntervalComplexNumericalScalar<RIS, RIM, CIS, CIM, RS, RM, CS, CM>, CIM extends IntervalComplexNumericalMatrix<RIS, RIM, CIS, CIM, RS, RM, CS, CM>, RS extends RealNumericalScalar<RS, RM, CS, CM>, RM extends RealNumericalMatrix<RS, RM, CS, CM>, CS extends ComplexNumericalScalar<RS, RM, CS, CM>, CM extends ComplexNumericalMatrix<RS, RM, CS, CM>> RIM create(
      RS[]rs, RIS ris) {
    int rowSize = rs.length;
    RIS[]riss = ris.createArray(rowSize);
    for (int i = 0; i < rowSize; i++) {
      riss[i] = ris.create(rs[i]);
    }

    return ris.createGrid(riss);
  }

  /**
   * Creates interval matrix.
   * 
   * @param rm RM
   * @param ris RIS
   * @return RIM
   * @param <RIS> 実区間スカラーの型
   * @param <RIM> 実区間行列の型
   * @param <CIS> 複素区間スカラーの型
   * @param <CIM> 複素区間行列の型
   * @param <RS> 実スカラーの型
   * @param <RM> 実行列の型
   * @param <CS> 複素スカラーの型
   * @param <CM> 複素行列の型
   */
  public static <RIS extends IntervalRealNumericalScalar<RIS, RIM, CIS, CIM, RS, RM, CS, CM>, RIM extends IntervalRealNumericalMatrix<RIS, RIM, CIS, CIM, RS, RM, CS, CM>, CIS extends IntervalComplexNumericalScalar<RIS, RIM, CIS, CIM, RS, RM, CS, CM>, CIM extends IntervalComplexNumericalMatrix<RIS, RIM, CIS, CIM, RS, RM, CS, CM>, RS extends RealNumericalScalar<RS, RM, CS, CM>, RM extends RealNumericalMatrix<RS, RM, CS, CM>, CS extends ComplexNumericalScalar<RS, RM, CS, CM>, CM extends ComplexNumericalMatrix<RS, RM, CS, CM>> RIM create(
      RM rm, RIS ris) {
    return create(rm.getElements(), ris);
  }

  /**
   * Creates interval matrix.
   * 
   * @param cs CS
   * @param ris RIS
   * @return RIM
   * @param <RIS> 実区間スカラーの型
   * @param <RIM> 実区間行列の型
   * @param <CIS> 複素区間スカラーの型
   * @param <CIM> 複素区間行列の型
   * @param <RS> 実スカラーの型
   * @param <RM> 実行列の型
   * @param <CS> 複素スカラーの型
   * @param <CM> 複素行列の型
   */
  public static <RIS extends IntervalRealNumericalScalar<RIS, RIM, CIS, CIM, RS, RM, CS, CM>, RIM extends IntervalRealNumericalMatrix<RIS, RIM, CIS, CIM, RS, RM, CS, CM>, CIS extends IntervalComplexNumericalScalar<RIS, RIM, CIS, CIM, RS, RM, CS, CM>, CIM extends IntervalComplexNumericalMatrix<RIS, RIM, CIS, CIM, RS, RM, CS, CM>, RS extends RealNumericalScalar<RS, RM, CS, CM>, RM extends RealNumericalMatrix<RS, RM, CS, CM>, CS extends ComplexNumericalScalar<RS, RM, CS, CM>, CM extends ComplexNumericalMatrix<RS, RM, CS, CM>> CIM create(
      CS[][] cs, RIS ris) {
    int rowSize = cs.length;
    int columnSize = cs[0].length;
    CIS cis = ris.toComplex();

    CIS[][] ciss = cis.createArray(rowSize, columnSize);
    for (int i = 0; i < rowSize; i++) {
      for (int j = 0; j < columnSize; j++) {
        ciss[i][j] = cis.create(cs[i][j]);
      }
    }

    return cis.createGrid(ciss);
  }

  /**
   * Creates interval matrix.
   * 
   * @param cs CS
   * @param ris RIS
   * @return RIM
   * @param <RIS> 実区間スカラーの型
   * @param <RIM> 実区間行列の型
   * @param <CIS> 複素区間スカラーの型
   * @param <CIM> 複素区間行列の型
   * @param <RS> 実スカラーの型
   * @param <RM> 実行列の型
   * @param <CS> 複素スカラーの型
   * @param <CM> 複素行列の型
   */
  public static <RIS extends IntervalRealNumericalScalar<RIS, RIM, CIS, CIM, RS, RM, CS, CM>, RIM extends IntervalRealNumericalMatrix<RIS, RIM, CIS, CIM, RS, RM, CS, CM>, CIS extends IntervalComplexNumericalScalar<RIS, RIM, CIS, CIM, RS, RM, CS, CM>, CIM extends IntervalComplexNumericalMatrix<RIS, RIM, CIS, CIM, RS, RM, CS, CM>, RS extends RealNumericalScalar<RS, RM, CS, CM>, RM extends RealNumericalMatrix<RS, RM, CS, CM>, CS extends ComplexNumericalScalar<RS, RM, CS, CM>, CM extends ComplexNumericalMatrix<RS, RM, CS, CM>> CIM create(
      CS[] cs, RIS ris) {
    int rowSize = cs.length;
    CIS cis = ris.toComplex();

    CIS[]ciss = cis.createArray(rowSize);
    for (int i = 0; i < rowSize; i++) {
      ciss[i] = cis.create(cs[i]);
    }

    return cis.createGrid(ciss);
  }

  /**
   * Creates interval matrix.
   * 
   * @param cm CM
   * @param ris RIS
   * @return CIM
   * @param <RIS> 実区間スカラーの型
   * @param <RIM> 実区間行列の型
   * @param <CIS> 複素区間スカラーの型
   * @param <CIM> 複素区間行列の型
   * @param <RS> 実スカラーの型
   * @param <RM> 実行列の型
   * @param <CS> 複素スカラーの型
   * @param <CM> 複素行列の型
   */
  public static <RIS extends IntervalRealNumericalScalar<RIS, RIM, CIS, CIM, RS, RM, CS, CM>, RIM extends IntervalRealNumericalMatrix<RIS, RIM, CIS, CIM, RS, RM, CS, CM>, CIS extends IntervalComplexNumericalScalar<RIS, RIM, CIS, CIM, RS, RM, CS, CM>, CIM extends IntervalComplexNumericalMatrix<RIS, RIM, CIS, CIM, RS, RM, CS, CM>, RS extends RealNumericalScalar<RS, RM, CS, CM>, RM extends RealNumericalMatrix<RS, RM, CS, CM>, CS extends ComplexNumericalScalar<RS, RM, CS, CM>, CM extends ComplexNumericalMatrix<RS, RM, CS, CM>> CIM create(
      CM cm, RIS ris) {
    return create(cm.getElements(), ris);
  }
}