Warning, /include/opencascade/math_Matrix.lxx is written in an unsupported language. File is not indexed.
0001 // Copyright (c) 1997-1999 Matra Datavision
0002 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0003 //
0004 // This file is part of Open CASCADE Technology software library.
0005 //
0006 // This library is free software; you can redistribute it and/or modify it under
0007 // the terms of the GNU Lesser General Public License version 2.1 as published
0008 // by the Free Software Foundation, with special exception defined in the file
0009 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0010 // distribution for complete text of the license and disclaimer of any warranty.
0011 //
0012 // Alternatively, this file may be used under the terms of Open CASCADE
0013 // commercial license or contractual agreement.
0014
0015 #include <math_NotSquare.hxx>
0016 #include <Standard_DimensionError.hxx>
0017 #include <Standard_DivideByZero.hxx>
0018
0019 //=================================================================================================
0020
0021 inline Standard_OStream& operator<<(Standard_OStream& o, const math_Matrix& mat)
0022 {
0023 mat.Dump(o);
0024 return o;
0025 }
0026
0027 //=================================================================================================
0028
0029 inline math_Matrix operator*(const double Left, const math_Matrix& Right)
0030 {
0031 return Right.Multiplied(Left);
0032 }
0033
0034 //=================================================================================================
0035
0036 inline const double& math_Matrix::Value(const int Row, const int Col) const
0037 {
0038 return Array.Value(Row, Col);
0039 }
0040
0041 //=================================================================================================
0042
0043 inline double& math_Matrix::Value(const int Row, const int Col)
0044 {
0045 return Array.Value(Row, Col);
0046 }
0047
0048 //=================================================================================================
0049
0050 inline int math_Matrix::RowNumber() const noexcept
0051 {
0052 return Array.NbRows();
0053 }
0054
0055 //=================================================================================================
0056
0057 inline int math_Matrix::ColNumber() const noexcept
0058 {
0059 return Array.NbColumns();
0060 }
0061
0062 //=================================================================================================
0063
0064 inline int math_Matrix::LowerRow() const noexcept
0065 {
0066 return Array.LowerRow();
0067 }
0068
0069 //=================================================================================================
0070
0071 inline int math_Matrix::UpperRow() const noexcept
0072 {
0073 return Array.UpperRow();
0074 }
0075
0076 //=================================================================================================
0077
0078 inline int math_Matrix::LowerCol() const noexcept
0079 {
0080 return Array.LowerCol();
0081 }
0082
0083 //=================================================================================================
0084
0085 inline int math_Matrix::UpperCol() const noexcept
0086 {
0087 return Array.UpperCol();
0088 }
0089
0090 //=================================================================================================
0091
0092 inline void math_Matrix::SetLower(const int LowerRow, const int LowerCol) noexcept
0093 {
0094 SetLowerRow(LowerRow);
0095 SetLowerCol(LowerCol);
0096 }
0097
0098 //=================================================================================================
0099
0100 inline math_Matrix::math_Matrix(const int LowerRow,
0101 const int UpperRow,
0102 const int LowerCol,
0103 const int UpperCol)
0104 : Array(LowerRow, UpperRow, LowerCol, UpperCol)
0105 {
0106 }
0107
0108 //=================================================================================================
0109
0110 inline math_Matrix::math_Matrix(const int LowerRow,
0111 const int UpperRow,
0112 const int LowerCol,
0113 const int UpperCol,
0114 const double InitialValue)
0115 : Array(LowerRow, UpperRow, LowerCol, UpperCol)
0116 {
0117 Array.Init(InitialValue);
0118 }
0119
0120 //=================================================================================================
0121
0122 inline math_Matrix::math_Matrix(void* const Tab,
0123 const int LowerRow,
0124 const int UpperRow,
0125 const int LowerCol,
0126 const int UpperCol)
0127 : Array(Tab, LowerRow, UpperRow, LowerCol, UpperCol)
0128 {
0129 }
0130
0131 //=================================================================================================
0132
0133 inline math_Matrix::math_Matrix(const math_Matrix& Other)
0134
0135 = default;
0136
0137 //=================================================================================================
0138
0139 inline math_Matrix::math_Matrix(math_Matrix&& Other) noexcept
0140 : Array(std::move(Other.Array))
0141 {
0142 }
0143
0144 //=================================================================================================
0145
0146 inline void math_Matrix::Init(const double InitialValue) noexcept
0147 {
0148 Array.Init(InitialValue);
0149 }
0150
0151 //=================================================================================================
0152
0153 inline void math_Matrix::SetLowerRow(const int LowerRow) noexcept
0154 {
0155 Array.SetLowerRow(LowerRow);
0156 }
0157
0158 //=================================================================================================
0159
0160 inline void math_Matrix::SetLowerCol(const int LowerCol) noexcept
0161 {
0162 Array.SetLowerCol(LowerCol);
0163 }
0164
0165 //=================================================================================================
0166
0167 inline void math_Matrix::Multiply(const double Right) noexcept
0168 {
0169 const int aLowerRow = Array.LowerRow();
0170 const int anUpperRow = Array.UpperRow();
0171 const int aLowerCol = Array.LowerCol();
0172 const int anUpperCol = Array.UpperCol();
0173
0174 for (int I = aLowerRow; I <= anUpperRow; I++)
0175 {
0176 for (int J = aLowerCol; J <= anUpperCol; J++)
0177 {
0178 Array(I, J) = Array(I, J) * Right;
0179 }
0180 }
0181 }
0182
0183 //=================================================================================================
0184
0185 inline math_Matrix math_Matrix::Multiplied(const double Right) const noexcept
0186 {
0187 const int aLowerRow = Array.LowerRow();
0188 const int anUpperRow = Array.UpperRow();
0189 const int aLowerCol = Array.LowerCol();
0190 const int anUpperCol = Array.UpperCol();
0191
0192 math_Matrix Result(aLowerRow, anUpperRow, aLowerCol, anUpperCol);
0193 for (int I = aLowerRow; I <= anUpperRow; I++)
0194 {
0195 for (int J = aLowerCol; J <= anUpperCol; J++)
0196 {
0197 Result.Array(I, J) = Array(I, J) * Right;
0198 }
0199 }
0200 return Result;
0201 }
0202
0203 //=================================================================================================
0204
0205 inline math_Matrix math_Matrix::TMultiplied(const double Right) const noexcept
0206 {
0207 const int aLowerRow = Array.LowerRow();
0208 const int anUpperRow = Array.UpperRow();
0209 const int aLowerCol = Array.LowerCol();
0210 const int anUpperCol = Array.UpperCol();
0211
0212 math_Matrix Result(aLowerRow, anUpperRow, aLowerCol, anUpperCol);
0213 for (int I = aLowerRow; I <= anUpperRow; I++)
0214 {
0215 for (int J = aLowerCol; J <= anUpperCol; J++)
0216 {
0217 Result.Array(I, J) = Array(I, J) * Right;
0218 }
0219 }
0220 return Result;
0221 }
0222
0223 //=================================================================================================
0224
0225 inline void math_Matrix::Divide(const double Right)
0226 {
0227 Standard_DivideByZero_Raise_if(std::abs(Right) <= RealEpsilon(),
0228 "math_Matrix::Divide() - zero divisor");
0229
0230 const int aLowerRow = Array.LowerRow();
0231 const int anUpperRow = Array.UpperRow();
0232 const int aLowerCol = Array.LowerCol();
0233 const int anUpperCol = Array.UpperCol();
0234
0235 for (int I = aLowerRow; I <= anUpperRow; I++)
0236 {
0237 for (int J = aLowerCol; J <= anUpperCol; J++)
0238 {
0239 Array(I, J) = Array(I, J) / Right;
0240 }
0241 }
0242 }
0243
0244 //=================================================================================================
0245
0246 inline math_Matrix math_Matrix::Divided(const double Right) const
0247 {
0248 Standard_DivideByZero_Raise_if(std::abs(Right) <= RealEpsilon(),
0249 "math_Matrix::Divided() - zero divisor");
0250 math_Matrix temp = Multiplied(1. / Right);
0251 return temp;
0252 }
0253
0254 //=================================================================================================
0255
0256 inline void math_Matrix::Add(const math_Matrix& Right)
0257 {
0258 Standard_DimensionError_Raise_if((RowNumber() != Right.RowNumber())
0259 || (ColNumber() != Right.ColNumber()),
0260 "math_Matrix::Add() - input matrix has different dimensions");
0261
0262 const int aLowerRow = Array.LowerRow();
0263 const int anUpperRow = Array.UpperRow();
0264 const int aLowerCol = Array.LowerCol();
0265 const int anUpperCol = Array.UpperCol();
0266
0267 int I2 = Right.LowerRow();
0268 for (int I = aLowerRow; I <= anUpperRow; I++)
0269 {
0270 int J2 = Right.LowerCol();
0271 for (int J = aLowerCol; J <= anUpperCol; J++)
0272 {
0273 Array(I, J) = Array(I, J) + Right.Array(I2, J2);
0274 J2++;
0275 }
0276 I2++;
0277 }
0278 }
0279
0280 //=================================================================================================
0281
0282 inline math_Matrix math_Matrix::Added(const math_Matrix& Right) const
0283 {
0284 Standard_DimensionError_Raise_if((RowNumber() != Right.RowNumber())
0285 || (ColNumber() != Right.ColNumber()),
0286 "math_Matrix::Added() - input matrix has different dimensions");
0287
0288 const int aLowerRow = Array.LowerRow();
0289 const int anUpperRow = Array.UpperRow();
0290 const int aLowerCol = Array.LowerCol();
0291 const int anUpperCol = Array.UpperCol();
0292
0293 math_Matrix Result(aLowerRow, anUpperRow, aLowerCol, anUpperCol);
0294
0295 int I2 = Right.LowerRow();
0296 for (int I = aLowerRow; I <= anUpperRow; I++)
0297 {
0298 int J2 = Right.LowerCol();
0299 for (int J = aLowerCol; J <= anUpperCol; J++)
0300 {
0301 Result.Array(I, J) = Array(I, J) + Right.Array(I2, J2);
0302 J2++;
0303 }
0304 I2++;
0305 }
0306 return Result;
0307 }
0308
0309 //=================================================================================================
0310
0311 inline void math_Matrix::Add(const math_Matrix& Left, const math_Matrix& Right)
0312 {
0313 Standard_DimensionError_Raise_if(
0314 (RowNumber() != Right.RowNumber()) || (ColNumber() != Right.ColNumber())
0315 || (Right.RowNumber() != Left.RowNumber()) || (Right.ColNumber() != Left.ColNumber()),
0316 "math_Matrix::Add() - matrices have incompatible dimensions");
0317
0318 const int aLowerRow = Array.LowerRow();
0319 const int anUpperRow = Array.UpperRow();
0320 const int aLowerCol = Array.LowerCol();
0321 const int anUpperCol = Array.UpperCol();
0322
0323 int I1 = Left.LowerRow();
0324 int I2 = Right.LowerRow();
0325 for (int I = aLowerRow; I <= anUpperRow; I++)
0326 {
0327 int J1 = Left.LowerCol();
0328 int J2 = Right.LowerCol();
0329 for (int J = aLowerCol; J <= anUpperCol; J++)
0330 {
0331 Array(I, J) = Left.Array(I1, J1) + Right.Array(I2, J2);
0332 J1++;
0333 J2++;
0334 }
0335 I1++;
0336 I2++;
0337 }
0338 }
0339
0340 //=================================================================================================
0341
0342 inline void math_Matrix::Subtract(const math_Matrix& Right)
0343 {
0344 Standard_DimensionError_Raise_if(
0345 (RowNumber() != Right.RowNumber()) || (ColNumber() != Right.ColNumber()),
0346 "math_Matrix::Subtract() - input matrix has different dimensions");
0347
0348 const int aLowerRow = Array.LowerRow();
0349 const int anUpperRow = Array.UpperRow();
0350 const int aLowerCol = Array.LowerCol();
0351 const int anUpperCol = Array.UpperCol();
0352
0353 int I2 = Right.LowerRow();
0354 for (int I = aLowerRow; I <= anUpperRow; I++)
0355 {
0356 int J2 = Right.LowerCol();
0357 for (int J = aLowerCol; J <= anUpperCol; J++)
0358 {
0359 Array(I, J) = Array(I, J) - Right.Array(I2, J2);
0360 J2++;
0361 }
0362 I2++;
0363 }
0364 }
0365
0366 //=================================================================================================
0367
0368 inline math_Matrix math_Matrix::Subtracted(const math_Matrix& Right) const
0369 {
0370 Standard_DimensionError_Raise_if(
0371 (RowNumber() != Right.RowNumber()) || (ColNumber() != Right.ColNumber()),
0372 "math_Matrix::Subtracted() - input matrix has different dimensions");
0373
0374 const int aLowerRow = Array.LowerRow();
0375 const int anUpperRow = Array.UpperRow();
0376 const int aLowerCol = Array.LowerCol();
0377 const int anUpperCol = Array.UpperCol();
0378
0379 math_Matrix Result(aLowerRow, anUpperRow, aLowerCol, anUpperCol);
0380
0381 int I2 = Right.LowerRow();
0382 for (int I = aLowerRow; I <= anUpperRow; I++)
0383 {
0384 int J2 = Right.LowerCol();
0385 for (int J = aLowerCol; J <= anUpperCol; J++)
0386 {
0387 Result.Array(I, J) = Array(I, J) - Right.Array(I2, J2);
0388 J2++;
0389 }
0390 I2++;
0391 }
0392 return Result;
0393 }
0394
0395 //=================================================================================================
0396
0397 inline void math_Matrix::Subtract(const math_Matrix& Left, const math_Matrix& Right)
0398 {
0399 Standard_DimensionError_Raise_if(
0400 (RowNumber() != Right.RowNumber()) || (ColNumber() != Right.ColNumber())
0401 || (Right.RowNumber() != Left.RowNumber()) || (Right.ColNumber() != Left.ColNumber()),
0402 "math_Matrix::Subtract() - matrices have incompatible dimensions");
0403
0404 const int aLowerRow = Array.LowerRow();
0405 const int anUpperRow = Array.UpperRow();
0406 const int aLowerCol = Array.LowerCol();
0407 const int anUpperCol = Array.UpperCol();
0408
0409 int I1 = Left.LowerRow();
0410 int I2 = Right.LowerRow();
0411 for (int I = aLowerRow; I <= anUpperRow; I++)
0412 {
0413 int J1 = Left.LowerCol();
0414 int J2 = Right.LowerCol();
0415 for (int J = aLowerCol; J <= anUpperCol; J++)
0416 {
0417 Array(I, J) = Left.Array(I1, J1) - Right.Array(I2, J2);
0418 J1++;
0419 J2++;
0420 }
0421 I1++;
0422 I2++;
0423 }
0424 }
0425
0426 //=================================================================================================
0427
0428 inline math_Matrix math_Matrix::Opposite() const
0429 {
0430 const int aLowerRow = Array.LowerRow();
0431 const int anUpperRow = Array.UpperRow();
0432 const int aLowerCol = Array.LowerCol();
0433 const int anUpperCol = Array.UpperCol();
0434
0435 math_Matrix Result(aLowerRow, anUpperRow, aLowerCol, anUpperCol);
0436
0437 for (int I = aLowerRow; I <= anUpperRow; I++)
0438 {
0439 for (int J = aLowerCol; J <= anUpperCol; J++)
0440 {
0441 Result.Array(I, J) = -Array(I, J);
0442 }
0443 }
0444 return Result;
0445 }
0446
0447 //=================================================================================================
0448
0449 inline void math_Matrix::Set(const int I1,
0450 const int I2,
0451 const int J1,
0452 const int J2,
0453 const math_Matrix& M)
0454 {
0455 Standard_DimensionError_Raise_if((I1 > I2) || (J1 > J2) || (I2 - I1 + 1 != M.RowNumber())
0456 || (J2 - J1 + 1 != M.ColNumber()),
0457 "math_Matrix::Set() - invalid indices");
0458
0459 int II = M.LowerRow();
0460 for (int I = I1; I <= I2; I++)
0461 {
0462 int JJ = M.LowerCol();
0463 for (int J = J1; J <= J2; J++)
0464 {
0465 Array(I, J) = M.Array(II, JJ);
0466 JJ++;
0467 }
0468 II++;
0469 }
0470 }
0471
0472 //=================================================================================================
0473
0474 inline void math_Matrix::SetDiag(const double Value)
0475 {
0476 math_NotSquare_Raise_if(RowNumber() != ColNumber(),
0477 "math_Matrix::SetDiag() - matrix is not square");
0478
0479 const int aLowerRow = Array.LowerRow();
0480 const int anUpperRow = Array.UpperRow();
0481
0482 for (int I = aLowerRow; I <= anUpperRow; I++)
0483 {
0484 Array(I, I) = Value;
0485 }
0486 }
0487
0488 //=================================================================================================
0489
0490 inline math_Matrix math_Matrix::Transposed() const
0491 {
0492 const int aLowerRow = Array.LowerRow();
0493 const int anUpperRow = Array.UpperRow();
0494 const int aLowerCol = Array.LowerCol();
0495 const int anUpperCol = Array.UpperCol();
0496
0497 math_Matrix Result(aLowerCol, anUpperCol, aLowerRow, anUpperRow);
0498
0499 for (int I = aLowerRow; I <= anUpperRow; I++)
0500 {
0501 for (int J = aLowerCol; J <= anUpperCol; J++)
0502 {
0503 Result.Array(J, I) = Array(I, J);
0504 }
0505 }
0506 return Result;
0507 }
0508
0509 //=================================================================================================
0510
0511 inline void math_Matrix::Multiply(const math_Matrix& Left, const math_Matrix& Right)
0512 {
0513 Standard_DimensionError_Raise_if(
0514 (Left.ColNumber() != Right.RowNumber()) || (RowNumber() != Left.RowNumber())
0515 || (ColNumber() != Right.ColNumber()),
0516 "math_Matrix::Multiply() - matrices have incompatible dimensions");
0517
0518 const int aLowerRow = Array.LowerRow();
0519 const int anUpperRow = Array.UpperRow();
0520 const int aLowerCol = Array.LowerCol();
0521 const int anUpperCol = Array.UpperCol();
0522
0523 Init(0.0);
0524
0525 // Cache-friendly i-k-j loop order for row-major matrix storage.
0526 // The inner loop accesses Right row-by-row (sequential memory access),
0527 // improving cache utilization significantly for large matrices.
0528 int I1 = Left.LowerRow();
0529 for (int I = aLowerRow; I <= anUpperRow; I++)
0530 {
0531 int J1 = Left.LowerCol();
0532 int I2 = Right.LowerRow();
0533 for (int K = Left.LowerCol(); K <= Left.UpperCol(); K++)
0534 {
0535 const double aLeftVal = Left.Array(I1, J1);
0536 int J2 = Right.LowerCol();
0537 for (int J = aLowerCol; J <= anUpperCol; J++)
0538 {
0539 Array(I, J) += aLeftVal * Right.Array(I2, J2);
0540 J2++;
0541 }
0542 J1++;
0543 I2++;
0544 }
0545 I1++;
0546 }
0547 }
0548
0549 //=================================================================================================
0550
0551 inline void math_Matrix::Multiply(const math_Matrix& Right)
0552 {
0553 Standard_DimensionError_Raise_if(
0554 ColNumber() != Right.RowNumber(),
0555 "math_Matrix::Multiply() - input matrix has incompatible dimensions");
0556
0557 const int aLowerRow = Array.LowerRow();
0558 const int anUpperRow = Array.UpperRow();
0559 const int aLowerCol = Array.LowerCol();
0560 const int anUpperCol = Array.UpperCol();
0561
0562 // Create a temporary copy to avoid corrupting our own data during calculation
0563 math_Matrix aTemp = *this;
0564 if (this == &Right)
0565 {
0566 Multiply(aTemp, aTemp);
0567 return;
0568 }
0569
0570 double Som;
0571 for (int I = aLowerRow; I <= anUpperRow; I++)
0572 {
0573 for (int J2 = Right.LowerCol(); J2 <= Right.UpperCol(); J2++)
0574 {
0575 Som = 0.0;
0576 int I2 = Right.LowerRow();
0577 for (int J = aLowerCol; J <= anUpperCol; J++)
0578 {
0579 Som += aTemp.Array(I, J) * Right.Array(I2, J2);
0580 I2++;
0581 }
0582 Array(I, J2) = Som;
0583 }
0584 }
0585 }
0586
0587 //=================================================================================================
0588
0589 inline math_Matrix math_Matrix::Multiplied(const math_Matrix& Right) const
0590 {
0591 Standard_DimensionError_Raise_if(
0592 ColNumber() != Right.RowNumber(),
0593 "math_Matrix::Multiplied() - matrices have incompatible dimensions");
0594
0595 const int aLowerRow = Array.LowerRow();
0596 const int anUpperRow = Array.UpperRow();
0597 const int aLowerCol = Array.LowerCol();
0598 const int anUpperCol = Array.UpperCol();
0599
0600 // Initialize result to zero
0601 math_Matrix Result(aLowerRow, anUpperRow, Right.LowerCol(), Right.UpperCol(), 0.0);
0602
0603 // Cache-friendly i-k-j loop order for row-major matrix storage.
0604 // The inner loop accesses Right row-by-row (sequential memory access),
0605 // improving cache utilization significantly for large matrices.
0606 for (int I = aLowerRow; I <= anUpperRow; I++)
0607 {
0608 int I2 = Right.LowerRow();
0609 for (int J = aLowerCol; J <= anUpperCol; J++)
0610 {
0611 const double aLeftVal = Array(I, J);
0612 int J2 = Right.LowerCol();
0613 for (int JR = Right.LowerCol(); JR <= Right.UpperCol(); JR++)
0614 {
0615 Result.Array(I, JR) += aLeftVal * Right.Array(I2, J2);
0616 J2++;
0617 }
0618 I2++;
0619 }
0620 }
0621 return Result;
0622 }
0623
0624 //=================================================================================================
0625
0626 inline math_Matrix math_Matrix::TMultiply(const math_Matrix& Right) const
0627 {
0628 Standard_DimensionError_Raise_if(
0629 RowNumber() != Right.RowNumber(),
0630 "math_Matrix::TMultiply() - matrices have incompatible dimensions");
0631
0632 const int aLowerRow = Array.LowerRow();
0633 const int anUpperRow = Array.UpperRow();
0634 const int aLowerCol = Array.LowerCol();
0635 const int anUpperCol = Array.UpperCol();
0636
0637 math_Matrix Result(aLowerCol, anUpperCol, Right.LowerCol(), Right.UpperCol());
0638
0639 double Som;
0640 for (int I = aLowerCol; I <= anUpperCol; I++)
0641 {
0642 for (int J2 = Right.LowerCol(); J2 <= Right.UpperCol(); J2++)
0643 {
0644 Som = 0.0;
0645 int I2 = Right.LowerRow();
0646 for (int J = aLowerRow; J <= anUpperRow; J++)
0647 {
0648 Som = Som + Array(J, I) * Right.Array(I2, J2);
0649 I2++;
0650 }
0651 Result.Array(I, J2) = Som;
0652 }
0653 }
0654 return Result;
0655 }
0656
0657 //=================================================================================================
0658
0659 inline void math_Matrix::TMultiply(const math_Matrix& TLeft, const math_Matrix& Right)
0660 {
0661 Standard_DimensionError_Raise_if(
0662 (TLeft.RowNumber() != Right.RowNumber()) || (RowNumber() != TLeft.ColNumber())
0663 || (ColNumber() != Right.ColNumber()),
0664 "math_Matrix::TMultiply() - matrices have incompatible dimensions");
0665
0666 const int aLowerRow = Array.LowerRow();
0667 const int anUpperRow = Array.UpperRow();
0668 const int aLowerCol = Array.LowerCol();
0669 const int anUpperCol = Array.UpperCol();
0670
0671 double Som;
0672 int I1 = TLeft.LowerCol();
0673 for (int I = aLowerRow; I <= anUpperRow; I++)
0674 {
0675 int J2 = Right.LowerCol();
0676 for (int J = aLowerCol; J <= anUpperCol; J++)
0677 {
0678 Som = 0.0;
0679 int J1 = TLeft.LowerRow();
0680 int I2 = Right.LowerRow();
0681 for (int K = TLeft.LowerRow(); K <= TLeft.UpperRow(); K++)
0682 {
0683 Som = Som + TLeft.Array(J1, I1) * Right.Array(I2, J2);
0684 J1++;
0685 I2++;
0686 }
0687 Array(I, J) = Som;
0688 J2++;
0689 }
0690 I1++;
0691 }
0692 }
0693
0694 //=================================================================================================
0695
0696 inline math_Matrix& math_Matrix::Initialized(const math_Matrix& Other)
0697 {
0698 (Other.Array).Copy(Array);
0699 return *this;
0700 }
0701
0702 //=================================================================================================
0703
0704 inline math_Matrix& math_Matrix::operator=(math_Matrix&& Other)
0705 {
0706 if (this == &Other)
0707 {
0708 return *this;
0709 }
0710
0711 if (Array.IsDeletable() && Other.Array.IsDeletable() && RowNumber() == Other.RowNumber()
0712 && ColNumber() == Other.ColNumber() && LowerRow() == Other.LowerRow()
0713 && LowerCol() == Other.LowerCol())
0714 {
0715 Array = std::move(Other.Array);
0716 }
0717 else
0718 {
0719 Initialized(Other);
0720 }
0721 return *this;
0722 }
0723
0724 //=================================================================================================
0725
0726 inline void math_Matrix::Transpose()
0727 {
0728 math_NotSquare_Raise_if(RowNumber() != ColNumber(),
0729 "math_Matrix::Transpose() - matrix is not square");
0730
0731 const int aLowerRow = Array.LowerRow();
0732 const int anUpperRow = Array.UpperRow();
0733 const int aLowerCol = Array.LowerCol();
0734 const int anUpperCol = Array.UpperCol();
0735
0736 int Row = aLowerRow;
0737 int Col = aLowerCol;
0738 SetLowerCol(aLowerRow);
0739 double Temp;
0740 for (int I = aLowerRow; I <= anUpperRow; I++)
0741 {
0742 for (int J = I; J <= anUpperCol; J++)
0743 {
0744 Temp = Array(I, J);
0745 Array(I, J) = Array(J, I);
0746 Array(J, I) = Temp;
0747 }
0748 }
0749 SetLowerRow(Col);
0750 SetLowerCol(Row);
0751 }
0752
0753 //=================================================================================================
0754
0755 inline void math_Matrix::Dump(Standard_OStream& o) const
0756 {
0757 const int aLowerRow = Array.LowerRow();
0758 const int anUpperRow = Array.UpperRow();
0759 const int aLowerCol = Array.LowerCol();
0760 const int anUpperCol = Array.UpperCol();
0761
0762 o << "math_Matrix of RowNumber = " << RowNumber();
0763 o << " and ColNumber = " << ColNumber() << "\n";
0764
0765 for (int I = aLowerRow; I <= anUpperRow; I++)
0766 {
0767 for (int J = aLowerCol; J <= anUpperCol; J++)
0768 {
0769 o << "math_Matrix ( " << I << ", " << J << " ) = ";
0770 o << Array(I, J) << "\n";
0771 }
0772 }
0773 }