Skip to content

Commit ac37b92

Browse files
authored
Merge pull request #4 from stefan-zobel/1.4.2-Snapshot
Merge 1.4.2 branch
2 parents 2fda439 + d588531 commit ac37b92

16 files changed

+306
-37
lines changed

pom.xml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>net.sourceforge.streamsupport</groupId>
55
<artifactId>jamu</artifactId>
66
<packaging>jar</packaging>
7-
<version>1.4.1</version>
7+
<version>1.4.2-SNAPSHOT</version>
88
<name>JAMU</name>
99
<description>Java Matrix Utilities built on top of Intel MKL</description>
1010
<url>https://github.com/stefan-zobel/JAMU/</url>
@@ -46,25 +46,22 @@
4646
<plugins>
4747
<plugin>
4848
<artifactId>maven-compiler-plugin</artifactId>
49-
<version>3.8.1</version>
49+
<version>3.12.1</version>
5050
<configuration>
51-
<source>1.7</source>
52-
<target>1.7</target>
51+
<source>1.8</source>
52+
<target>1.8</target>
5353
</configuration>
5454
</plugin>
5555
<plugin>
5656
<groupId>org.apache.maven.plugins</groupId>
5757
<artifactId>maven-javadoc-plugin</artifactId>
58-
<version>3.2.0</version>
58+
<version>3.5.0</version>
5959
<executions>
6060
<execution>
6161
<id>attach-javadocs</id>
6262
<goals>
6363
<goal>jar</goal>
6464
</goals>
65-
<configuration>
66-
<doclint>none</doclint>
67-
</configuration>
6865
</execution>
6966
</executions>
7067
</plugin>

src/main/java/net/jamu/matrix/ComplexMatrixD.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ public interface ComplexMatrixD extends MatrixDimensions, ComplexMatrixDConduct
638638
ComplexMatrixD expm();
639639

640640
/**
641-
* Hadamard product {@code C = A} &SmallCircle; {@code B} (also known as
641+
* Hadamard product {@code C = A} \u2218 {@code B} (also known as
642642
* element-wise product) of this matrix (A) and B.
643643
*
644644
* @param B

src/main/java/net/jamu/matrix/ComplexMatrixDConduct.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ public interface ComplexMatrixDConduct {
339339
ComplexMatrixD inverse();
340340

341341
/**
342-
* Hadamard product {@code A} &SmallCircle; {@code B} (also known as
342+
* Hadamard product {@code A} \u2218 {@code B} (also known as
343343
* element-wise product) of this matrix (A) and B.
344344
*
345345
* @param B

src/main/java/net/jamu/matrix/ComplexMatrixF.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ public interface ComplexMatrixF extends MatrixDimensions, ComplexMatrixFConduct
638638
ComplexMatrixF expm();
639639

640640
/**
641-
* Hadamard product {@code C = A} &SmallCircle; {@code B} (also known as
641+
* Hadamard product {@code C = A} \u2218 {@code B} (also known as
642642
* element-wise product) of this matrix (A) and B.
643643
*
644644
* @param B

src/main/java/net/jamu/matrix/ComplexMatrixFConduct.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ public interface ComplexMatrixFConduct {
339339
ComplexMatrixF inverse();
340340

341341
/**
342-
* Hadamard product {@code A} &SmallCircle; {@code B} (also known as
342+
* Hadamard product {@code A} \u2218 {@code B} (also known as
343343
* element-wise product) of this matrix (A) and B.
344344
*
345345
* @param B
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2018 Stefan Zobel
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package net.jamu.matrix;
17+
18+
/**
19+
* Represents a function that accepts one {@code double} argument and produces a
20+
* {@code double} result.
21+
*
22+
* @since 1.4.2
23+
*/
24+
@FunctionalInterface
25+
public interface DFunction {
26+
/**
27+
* Applies this function to the given argument.
28+
*
29+
* @param x
30+
* the function argument
31+
* @return the function result
32+
*/
33+
double apply(double x);
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2018 Stefan Zobel
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package net.jamu.matrix;
17+
18+
/**
19+
* Represents a function that accepts one {@code float} argument and produces a
20+
* {@code float} result.
21+
*
22+
* @since 1.4.2
23+
*/
24+
@FunctionalInterface
25+
public interface FFunction {
26+
/**
27+
* Applies this function to the given argument.
28+
*
29+
* @param x
30+
* the function argument
31+
* @return the function result
32+
*/
33+
float apply(float x);
34+
}

src/main/java/net/jamu/matrix/Matrices.java

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019, 2023 Stefan Zobel
2+
* Copyright 2019, 2024 Stefan Zobel
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -3499,6 +3499,34 @@ public static ComplexMatrixF sumRows(ComplexMatrixF A) {
34993499
return s;
35003500
}
35013501

3502+
/**
3503+
* Returns a {@code 1 x A.numColumns()} matrix that contains the average of
3504+
* the row sums of matrix {@code A}.
3505+
*
3506+
* @param A
3507+
* the matrix whose average of the row sums should be computed
3508+
* @return a new matrix of dimension {@code 1 x A.numColumns()} that
3509+
* contains the average of the row sums of matrix {@code A}
3510+
* @since 1.4.2
3511+
*/
3512+
public static MatrixD rowsAverage(MatrixD A) {
3513+
return sumRows(A).scaleInplace(A.numRows());
3514+
}
3515+
3516+
/**
3517+
* Returns a {@code 1 x A.numColumns()} matrix that contains the average of
3518+
* the row sums of matrix {@code A}.
3519+
*
3520+
* @param A
3521+
* the matrix whose average of the row sums should be computed
3522+
* @return a new matrix of dimension {@code 1 x A.numColumns()} that
3523+
* contains the average of the row sums of matrix {@code A}
3524+
* @since 1.4.2
3525+
*/
3526+
public static MatrixF rowsAverage(MatrixF A) {
3527+
return sumRows(A).scaleInplace(A.numRows());
3528+
}
3529+
35023530
/**
35033531
* Returns a {@code A.numRows() x 1} matrix that contains the column sums of
35043532
* matrix {@code A}.
@@ -3617,6 +3645,34 @@ public static ComplexMatrixF sumColumns(ComplexMatrixF A) {
36173645
return s;
36183646
}
36193647

3648+
/**
3649+
* Returns a {@code A.numRows() x 1} matrix that contains the average of the
3650+
* column sums of matrix {@code A}.
3651+
*
3652+
* @param A
3653+
* the matrix whose average of column sums should be computed
3654+
* @return a new matrix of dimension {@code A.numRows() x 1} that contains
3655+
* the average of the column sums of matrix {@code A}
3656+
* @since 1.4.2
3657+
*/
3658+
public static MatrixD colsAverage(MatrixD A) {
3659+
return sumColumns(A).scaleInplace(A.numColumns());
3660+
}
3661+
3662+
/**
3663+
* Returns a {@code A.numRows() x 1} matrix that contains the average of the
3664+
* column sums of matrix {@code A}.
3665+
*
3666+
* @param A
3667+
* the matrix whose average of column sums should be computed
3668+
* @return a new matrix of dimension {@code A.numRows() x 1} that contains
3669+
* the average of the column sums of matrix {@code A}
3670+
* @since 1.4.2
3671+
*/
3672+
public static MatrixF colsAverage(MatrixF A) {
3673+
return sumColumns(A).scaleInplace(A.numColumns());
3674+
}
3675+
36203676
private static boolean checkApproxEqualArgs(MatrixDimensions A, MatrixDimensions B, double relTol, double absTol) {
36213677
if (relTol < 0.0 || Double.isNaN(relTol) || Double.isInfinite(relTol)) {
36223678
throw new IllegalArgumentException("illegal relTol : " + relTol);

src/main/java/net/jamu/matrix/MatrixD.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019, 2023 Stefan Zobel
2+
* Copyright 2019, 2024 Stefan Zobel
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -604,7 +604,7 @@ public interface MatrixD extends MatrixDimensions, MatrixDConduct {
604604
MatrixD expm();
605605

606606
/**
607-
* Hadamard product {@code C = A} &SmallCircle; {@code B} (also known as
607+
* Hadamard product {@code C = A} \u2218 {@code B} (also known as
608608
* element-wise product) of this matrix (A) and B.
609609
*
610610
* @param B
@@ -683,6 +683,17 @@ public interface MatrixD extends MatrixDimensions, MatrixDConduct {
683683
*/
684684
MatrixD clampInplace(double min, double max);
685685

686+
/**
687+
* {@code A = f(A)} where the scalar function {@code f} is applied to each
688+
* element of {@code A}.
689+
*
690+
* @param f
691+
* the scalar function to apply to each element of this matrix
692+
* @return this matrix (mutated)
693+
* @since 1.4.2
694+
*/
695+
MatrixD mapInplace(DFunction f);
696+
686697
/**
687698
* Set all elements <code>|x<sub>ij</sub>| &le; k * 2<sup>-53</sup></code>
688699
* ({@code k} times the machine epsilon for doubles) to {@code 0.0} where

src/main/java/net/jamu/matrix/MatrixDBase.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019, 2023 Stefan Zobel
2+
* Copyright 2019, 2024 Stefan Zobel
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -657,6 +657,18 @@ public MatrixD clampInplace(double min, double max) {
657657
return this;
658658
}
659659

660+
/**
661+
* {@inheritDoc}
662+
*/
663+
@Override
664+
public MatrixD mapInplace(DFunction f) {
665+
double[] _a = a;
666+
for (int i = 0; i < _a.length; ++i) {
667+
_a[i] = f.apply(_a[i]);
668+
}
669+
return this;
670+
}
671+
660672
/**
661673
* {@inheritDoc}
662674
*/
@@ -1027,6 +1039,14 @@ public MatrixD abs() {
10271039
return m;
10281040
}
10291041

1042+
/**
1043+
* {@inheritDoc}
1044+
*/
1045+
@Override
1046+
public MatrixD map(DFunction f) {
1047+
return copy().mapInplace(f);
1048+
}
1049+
10301050
/**
10311051
* {@inheritDoc}
10321052
*/

src/main/java/net/jamu/matrix/MatrixDConduct.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020, 2023 Stefan Zobel
2+
* Copyright 2020, 2024 Stefan Zobel
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -330,7 +330,7 @@ public interface MatrixDConduct {
330330
MatrixD inverse();
331331

332332
/**
333-
* Hadamard product {@code A} &SmallCircle; {@code B} (also known as
333+
* Hadamard product {@code A} \u2218 {@code B} (also known as
334334
* element-wise product) of this matrix (A) and B.
335335
*
336336
* @param B
@@ -341,7 +341,7 @@ public interface MatrixDConduct {
341341
MatrixD hadamard(MatrixD B);
342342

343343
/**
344-
* <code>A</code> &SmallCircle; <code>B<sup>T</sup></code> Hadamard
344+
* <code>A</code> \u2218 <code>B<sup>T</sup></code> Hadamard
345345
* multiplication (also known as element-wise product) between this matrix
346346
* ({@code A}) and the transpose of {@code B} (<code>B<sup>T</sup></code>).
347347
*
@@ -353,7 +353,7 @@ public interface MatrixDConduct {
353353
MatrixD hadamardTransposed(MatrixD B);
354354

355355
/**
356-
* <code>A<sup>T</sup></code> &SmallCircle; <code>B</code> Hadamard
356+
* <code>A<sup>T</sup></code> \u2218 <code>B</code> Hadamard
357357
* multiplication (also known as element-wise product) between this matrix
358358
* ({@code A}) transposed (<code>A<sup>T</sup></code>) and {@code B}.
359359
*
@@ -364,6 +364,18 @@ public interface MatrixDConduct {
364364
*/
365365
MatrixD transposedHadamard(MatrixD B);
366366

367+
/**
368+
* Returns {@code f(A)} where the scalar function {@code f} is applied to
369+
* each element on a copy of {@code A}.
370+
*
371+
* @param f
372+
* the scalar function to apply to each element on a copy of this
373+
* matrix
374+
* @return a copy of this matrix where f has been applied to each element
375+
* @since 1.4.2
376+
*/
377+
MatrixD map(DFunction f);
378+
367379
/**
368380
* Reshapes this matrix into a new matrix of dimension {@code rows x cols}
369381
* where the elements in this matrix are read in Fortran-style column-major

src/main/java/net/jamu/matrix/MatrixF.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019, 2023 Stefan Zobel
2+
* Copyright 2019, 2024 Stefan Zobel
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -604,7 +604,7 @@ public interface MatrixF extends MatrixDimensions, MatrixFConduct {
604604
MatrixF expm();
605605

606606
/**
607-
* Hadamard product {@code C = A} &SmallCircle; {@code B} (also known as
607+
* Hadamard product {@code C = A} \u2218 {@code B} (also known as
608608
* element-wise product) of this matrix (A) and B.
609609
*
610610
* @param B
@@ -683,6 +683,17 @@ public interface MatrixF extends MatrixDimensions, MatrixFConduct {
683683
*/
684684
MatrixF clampInplace(float min, float max);
685685

686+
/**
687+
* {@code A = f(A)} where the scalar function {@code f} is applied to each
688+
* element of {@code A}.
689+
*
690+
* @param f
691+
* the scalar function to apply to each element of this matrix
692+
* @return this matrix (mutated)
693+
* @since 1.4.2
694+
*/
695+
MatrixF mapInplace(FFunction f);
696+
686697
/**
687698
* Set all elements <code>|x<sub>ij</sub>| &le; k * 2<sup>-24</sup></code>
688699
* ({@code k} times the machine epsilon for floats) to {@code 0.0f} where

0 commit comments

Comments
 (0)