@@ -1518,75 +1518,83 @@ public double trace()
1518
1518
}
1519
1519
1520
1520
/**
1521
- * Applys the given operator to all elements, modifying this Matrix.
1522
- * @param operator Operator to be applied
1523
- * @throws NullPointerException iff operator == null
1521
+ * Applys the given operator to all elements, returning a new Matrix.
1522
+ * @param operator Operator to be applied to this Matrix and B
1523
+ * @return new Matrix with the result
1524
+ * @throws NullPointerException iff operator == null or B == null
1525
+ * @see {@link #transformEquals(DoubleUnaryOperator)}
1526
+ * to modify this Matrix instead of returning a new one
1524
1527
*/
1525
- public void transform (final DoubleUnaryOperator operator )
1528
+ public Matrix transform (final DoubleUnaryOperator operator )
1526
1529
{
1530
+ final Matrix M = new Matrix (this .m , this .n );
1527
1531
for (int i = 0 ; i < this .m ; i ++)
1528
1532
{
1529
1533
for (int j = 0 ; j < this .n ; j ++)
1530
1534
{
1531
- this .A [i ][j ] = operator .applyAsDouble (this .A [i ][j ]);
1535
+ M .A [i ][j ] = operator .applyAsDouble (this .A [i ][j ]);
1532
1536
}
1533
1537
}
1538
+ return M ;
1534
1539
}
1535
1540
1536
1541
/**
1537
- * Applys the given operator to all elements, returning a new Matrix.
1542
+ * Applys the given operator to all elements, modifying this Matrix.
1538
1543
* @param operator Operator to be applied
1539
- * @return new Matrix with the result
1540
1544
* @throws NullPointerException iff operator == null
1545
+ * @see {@link #transform(DoubleUnaryOperator)}
1546
+ * to return a new Matrix instead of modifying this Matrix
1541
1547
*/
1542
- public Matrix transformEquals (final DoubleUnaryOperator operator )
1548
+ public void transformEquals (final DoubleUnaryOperator operator )
1543
1549
{
1544
- final Matrix M = new Matrix (this .m , this .n );
1545
1550
for (int i = 0 ; i < this .m ; i ++)
1546
1551
{
1547
1552
for (int j = 0 ; j < this .n ; j ++)
1548
1553
{
1549
- M .A [i ][j ] = operator .applyAsDouble (this .A [i ][j ]);
1554
+ this .A [i ][j ] = operator .applyAsDouble (this .A [i ][j ]);
1550
1555
}
1551
1556
}
1552
- return M ;
1553
1557
}
1554
1558
1555
1559
/**
1556
- * Applys the given operator to all elements, modifying this Matrix.
1560
+ * Applys the given operator to all elements, returning a new Matrix.
1557
1561
* @param B another Matrix
1558
1562
* @param operator Operator to be applied
1563
+ * @return new Matrix with the result
1559
1564
* @throws NullPointerException iff operator == null
1565
+ * @see {@link #transformEquals(Matrix, DoubleBinaryOperator)}
1566
+ * to modify this Matrix instead of returning a new one
1560
1567
*/
1561
- public void transform (final Matrix B , final DoubleBinaryOperator operator )
1568
+ public Matrix transform (final Matrix B , final DoubleBinaryOperator operator )
1562
1569
{
1570
+ final Matrix M = new Matrix (this .m , this .n );
1563
1571
for (int i = 0 ; i < this .m ; i ++)
1564
1572
{
1565
1573
for (int j = 0 ; j < this .n ; j ++)
1566
1574
{
1567
- this .A [i ][j ] = operator .applyAsDouble (this .A [i ][j ], B .A [i ][j ]);
1575
+ M .A [i ][j ] = operator .applyAsDouble (this .A [i ][j ], B .A [i ][j ]);
1568
1576
}
1569
1577
}
1578
+ return M ;
1570
1579
}
1571
1580
1572
1581
/**
1573
- * Applys the given operator to all elements, returning a new Matrix.
1582
+ * Applys the given operator to all elements, modifying this Matrix.
1574
1583
* @param B another Matrix
1575
- * @param operator Operator to be applied
1576
- * @return new Matrix with the result
1577
- * @throws NullPointerException iff operator == null
1584
+ * @param operator Operator to be applied to this Matrix and B
1585
+ * @throws NullPointerException iff operator == null or B == null
1586
+ * @see {@link #transform(Matrix, DoubleBinaryOperator)}
1587
+ * to return a new Matrix instead of modifying this Matrix
1578
1588
*/
1579
- public Matrix transformEquals (final Matrix B , final DoubleBinaryOperator operator )
1589
+ public void transformEquals (final Matrix B , final DoubleBinaryOperator operator )
1580
1590
{
1581
- final Matrix M = new Matrix (this .m , this .n );
1582
1591
for (int i = 0 ; i < this .m ; i ++)
1583
1592
{
1584
1593
for (int j = 0 ; j < this .n ; j ++)
1585
1594
{
1586
- M .A [i ][j ] = operator .applyAsDouble (this .A [i ][j ], B .A [i ][j ]);
1595
+ this .A [i ][j ] = operator .applyAsDouble (this .A [i ][j ], B .A [i ][j ]);
1587
1596
}
1588
1597
}
1589
- return M ;
1590
1598
}
1591
1599
1592
1600
/**
0 commit comments