matrix property Null safety

NormalArgOperation matrix
final

Implementation

static final NormalArgOperation matrix = NormalArgOperation(
    maxOneByteOpcodes: 0,
    arg: ArgAlternates(children: [
      KeyArg(
          key: Operations.n0,
          child: ArgDone((m) {
            for (final mat in (m as Model15).matrices) {
              mat.resize(m, 0, 0);
            }
          })),
      KeyArg(
          key: Operations.n1,
          child: ArgDone((m) {
            m.memory.registers[0] =
                m.memory.registers[1] = Value.fromDouble(1);
          })),
      KeyArg(
          key: Operations.n2,
          child: ArgDone((m) {
            final mat = _getMatrixFromValue(m as Model15, m.x);
            mat.convertToZTilde(m);
            m.needsSave = true;
          })),
      KeyArg(
          key: Operations.n3,
          child: ArgDone((m) {
            final mat = _getMatrixFromValue(m as Model15, m.x);
            mat.convertFromZTilde(m);
            m.needsSave = true;
          })),
      KeyArg(
          key: Operations.n4,
          child: ArgDone((m) {
            final mat = _getMatrixFromValue(m as Model15, m.x);
            mat.transpose();
            m.needsSave = true;
          })),
      KeyArg(
          key: Operations.n5,
          child: ArgDone((m) {
            final result = (m as Model15).matrices[m.resultMatrix];
            final x = _getMatrixFromValue(m, m.x);
            final y = _getMatrixFromValue(m, m.y);
            final yt = TransposeMatrix(y);
            _matrixMultiply(m, x, yt, result);
            m.popSetResultX = Value.fromMatrix(m.resultMatrix);
          })),
      KeyArg(
          key: Operations.n6,
          child: ArgDone((m) {
            final result = (m as Model15).matrices[m.resultMatrix];
            final x = _getMatrixFromValue(m, m.x);
            final y = _getMatrixFromValue(m, m.y);
            if (result == x || result == y) {
              throw CalculatorError(11);
            }
            if (y.columns != x.rows) {
              throw CalculatorError(11);
            }
            if (result.rows != y.rows || result.columns != x.columns) {
              throw CalculatorError(11);
            }
            result.residual(y, x);
            m.popSetResultX = Value.fromMatrix(m.resultMatrix);
          })),
      KeyArg(
          key: Operations.n7,
          child: ArgDone((m) {
            final mat = m.x.asMatrix;
            if (mat != null) {
              m.resultXF = linalg.rowNorm((m as Model15).matrices[mat]);
            } else {
              m.program.skipIfRunning();
            }
          })),
      KeyArg(
          key: Operations.n8,
          child: ArgDone((m) {
            final mat = m.x.asMatrix;
            if (mat != null) {
              m.resultXF = linalg.frobeniusNorm((m as Model15).matrices[mat]);
            } else {
              m.program.skipIfRunning();
            }
          })),
      KeyArg(
          key: Operations.n9,
          child: ArgDone((m) {
            final mat = m.x.asMatrix;
            if (mat == null) {
              throw CalculatorError(11);
            }
            final result = (m as Model15).matrices[m.resultMatrix];
            result.copyFrom(m, m.matrices[mat]);
            m.resultXF = linalg.determinant(result);
          })),
    ]),
    name: 'MATRIX');