File tree Expand file tree Collapse file tree 1 file changed +26
-6
lines changed
Expand file tree Collapse file tree 1 file changed +26
-6
lines changed Original file line number Diff line number Diff line change @@ -97,19 +97,39 @@ public function __toString()
9797 * @param Matrix|int|float $value Matrix or scalar to add to this matrix
9898 * @return Matrix
9999 * @throws MatrixException
100+ * @deprecated
100101 */
101102 public function add ($ value )
102103 {
103104 if ($ value instanceof Matrix) {
104- if ($ this ->rows != $ value ->rows || $ this ->columns != $ value ->columns ) {
105- throw new MatrixException ('Cannot add two matrices of different size. ' );
106- }
105+ return $ this ->addMatrix ($ value );
106+ }
107107
108- return $ this ->map (function ($ element , $ i , $ j ) use ($ value ) {
109- return $ element + $ value ->get ($ i , $ j );
110- });
108+ return $ this ->addScalar ($ value );
109+ }
110+
111+ /**
112+ * @param Matrix $value
113+ * @return Matrix
114+ * @throws MatrixException
115+ */
116+ public function addMatrix (Matrix $ value )
117+ {
118+ if ($ this ->rows != $ value ->rows || $ this ->columns != $ value ->columns ) {
119+ throw new MatrixException ('Cannot add two matrices of different size. ' );
111120 }
112121
122+ return $ this ->map (function ($ element , $ i , $ j ) use ($ value ) {
123+ return $ element + $ value ->get ($ i , $ j );
124+ });
125+ }
126+
127+ /**
128+ * @param float $value
129+ * @return Matrix
130+ */
131+ public function addScalar ($ value )
132+ {
113133 return $ this ->map (function ($ element ) use ($ value ) {
114134 return $ element + $ value ;
115135 });
You can’t perform that action at this time.
0 commit comments