Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyword Spotting Application #2001

Open
wants to merge 137 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
b6c4590
implemented ComplexDouble, added LibMatrixFourier
jessicapriebe Nov 27, 2023
189208c
added pow for ComplexDouble, updated fft
jessicapriebe Nov 27, 2023
e73709e
added complexDouble functions, simple Test
jessicapriebe Nov 27, 2023
5f03898
TODO: length of non power of two, added test
jessicapriebe Nov 27, 2023
d185a10
implemented fft2d + simple test
jessicapriebe Dec 11, 2023
ed99a8a
second test fft2d
jessicapriebe Dec 11, 2023
51c95a4
added numpy function to create fft output to feed in java test. added…
fzoepffel Dec 17, 2023
e46c73b
added execution time checker
fzoepffel Dec 17, 2023
f61bcd4
fixed fft + fft2d
jessicapriebe Dec 18, 2023
0b2d4bf
merged
jessicapriebe Dec 18, 2023
8d959fc
added ifft and tests
fzoepffel Dec 18, 2023
b652af3
added 2D ifft and tests
fzoepffel Dec 18, 2023
d7399ca
added test for 2dfft
fzoepffel Dec 18, 2023
f4b1207
added dml builtin stuff
fzoepffel Dec 18, 2023
809e2d9
removed complexDouble.pow
jessicapriebe Dec 18, 2023
bb79afe
added fft matrixblock 1 dim
jessicapriebe Dec 18, 2023
f79d005
fft for arrays with non-power-of-two length
Dec 18, 2023
b5a908f
fft matrixblock now supports both dim
jessicapriebe Dec 19, 2023
e767f10
Merge branch 'main' of https://github.com/fzoepffel/systemds into main
jessicapriebe Dec 19, 2023
ddcdec9
added ifft_one_dim MatrixBlock
jessicapriebe Dec 19, 2023
9478200
improved all fft MatrixBlock functions + separated from complex doubl…
jessicapriebe Dec 20, 2023
011568f
FastMath
jessicapriebe Dec 21, 2023
f6ae689
fft integration in systemds
jessicapriebe Dec 21, 2023
e51c825
fixed a integration bug and adjusted tests on csv files to new functions
fzoepffel Dec 22, 2023
b828668
Delete src/main/java/org/apache/sysds/runtime/matrix/data/LibMatrixFo…
mufwan Jan 14, 2024
8335fb7
Delete src/test/java/org/apache/sysds/test/component/matrix/Fourier2T…
mufwan Jan 14, 2024
a8ae448
ifft integration in dml
fzoepffel Jan 15, 2024
edd5a0b
Merge branches 'main' and 'main' of https://github.com/fzoepffel/syst…
fzoepffel Jan 15, 2024
45e2a75
dml integration ifft
fzoepffel Jan 15, 2024
f9c3b70
removed complexDouble
fzoepffel Jan 15, 2024
42faba1
beautified
jessicapriebe Jan 15, 2024
d1deac8
stft
mufwan Jan 16, 2024
3bf7b66
fft and ifft with double[] array
jessicapriebe Jan 17, 2024
602c749
removed old fft and ifft + tests
jessicapriebe Jan 17, 2024
d2edaef
stft with double[] array
jessicapriebe Jan 17, 2024
af67b41
some styling
jessicapriebe Jan 17, 2024
7590834
switch cases
jessicapriebe Jan 17, 2024
465d3e4
undo recent change in pom.xml
jessicapriebe Jan 17, 2024
d11e598
added licence
jessicapriebe Jan 17, 2024
3eb8677
removed json
jessicapriebe Jan 17, 2024
f21b4ed
tab indentation
jessicapriebe Jan 18, 2024
fc08367
java doc LibCommonsMath and LibMatrixFourier
jessicapriebe Jan 18, 2024
c79f0fd
updated stft branch and deleted from main
jessicapriebe Jan 18, 2024
57b1125
adjusted tests with files
fzoepffel Jan 19, 2024
b063424
added tests
jessicapriebe Jan 20, 2024
1f46e22
updated tests
jessicapriebe Jan 20, 2024
c6bf52d
iterative implementations
jessicapriebe Jan 21, 2024
8f240eb
integrated 2 inputs for ifft
fzoepffel Jan 21, 2024
3926eac
added one input and two input ifft to dml
fzoepffel Jan 22, 2024
9321a32
formatting
jessicapriebe Jan 23, 2024
26fcd20
removed FourierTestLarge
jessicapriebe Jan 23, 2024
7f71ac9
added java doc fft_one_dim
jessicapriebe Jan 24, 2024
5c3ae0b
Merge branch 'main' into main
fzoepffel Feb 8, 2024
a67f006
reversed formatting in functionop
fzoepffel Feb 8, 2024
06a2f94
Revert "reversed formatting in functionop"
fzoepffel Feb 8, 2024
e6085f9
Revert "formatting"
fzoepffel Feb 8, 2024
9667031
reverse formatting in LibCommonsMath
fzoepffel Feb 8, 2024
bc6d618
BuiltinFunctionExpression reverse formatting
fzoepffel Feb 8, 2024
ba7bd19
reversed formatting of CPInstructionParser
fzoepffel Feb 8, 2024
dbf01dd
reverse formatting CPInstruction
fzoepffel Feb 8, 2024
1120e78
reversed formatting PrivacyPropagator
fzoepffel Feb 8, 2024
10e6462
second time reverse formatting LibcommonsMath
fzoepffel Feb 8, 2024
045dcd5
reverse formatting MultiReturnBuiltinCPInstruction
fzoepffel Feb 8, 2024
3f531ff
last adjustments
fzoepffel Feb 9, 2024
f34f02c
added linearized fft and ifft
jessicapriebe Feb 15, 2024
25e4168
added formatting for LibMatrixFourier and FourierTest
jessicapriebe Feb 15, 2024
18462b5
fft_linearized and ifft_linearized dml integration
mufwan Feb 15, 2024
bf99d6b
purposeless bracket adjusted
fzoepffel Feb 17, 2024
8d514df
added overloads for computeIFFT and computeIFFT_LINEARIZED, removed i…
fzoepffel Feb 17, 2024
2fefb47
Update BuiltinFunctionExpression.java
mufwan Feb 17, 2024
c264c31
Update LibCommonsMath.java
mufwan Feb 17, 2024
b86eee8
added parallelization
jessicapriebe Feb 18, 2024
2cc8fc3
split fft_one_dim into smaller methods
jessicapriebe Feb 18, 2024
9b94f25
threading improved
fzoepffel Feb 19, 2024
8bed34c
improved parallelization
jessicapriebe Feb 19, 2024
ca839c9
split fft_one_dim into smaller methods
jessicapriebe Feb 19, 2024
eaa5798
added caching
jessicapriebe Feb 19, 2024
ec92b8f
adjusted caching
jessicapriebe Feb 20, 2024
931b78d
formatting
jessicapriebe Feb 20, 2024
8fe1f3b
Your commit message
mufwan Jan 20, 2024
5a1c2b6
inter arrays outside of loop + tab
jessicapriebe Jan 21, 2024
a2b08e2
adjusted to iterative fft impl
jessicapriebe Jan 21, 2024
714eb46
stft complex values
jessicapriebe Jan 22, 2024
76103b1
stft complex values
jessicapriebe Jan 22, 2024
cbd26b4
stft dml
mufwan Feb 12, 2024
5fc3c86
stft dml
mufwan Feb 12, 2024
ce6239f
stft dml integration
mufwan Feb 13, 2024
65043e7
handle zero matrix
mufwan Feb 14, 2024
be266e7
apply stft to each row
mufwan Feb 15, 2024
682edbc
classifier for keyword spotting
mufwan Feb 16, 2024
297b815
update stft
mufwan Feb 17, 2024
bb4f520
add parallelization
mufwan Feb 19, 2024
48eec91
Fixed error
mufwan Feb 19, 2024
12297d0
add threads
mufwan Feb 19, 2024
e1cc9a2
stft without double[][]
mufwan Jan 19, 2024
8783d84
styling
jessicapriebe Jan 20, 2024
baf7df7
styling
jessicapriebe Jan 20, 2024
2c6fb3a
added ReaderWavFile, LibMatrixKeywordSpotting
jessicapriebe Jan 16, 2024
fc1a7ec
merged stft into application
jessicapriebe Jan 16, 2024
a6b4d4e
merged stft into application
jessicapriebe Jan 16, 2024
f4a651a
tab indentation new files
jessicapriebe Jan 18, 2024
53be83e
styling
jessicapriebe Jan 20, 2024
c9f0126
added zip temporarily
jessicapriebe Jan 20, 2024
124b964
use url for zip
jessicapriebe Feb 14, 2024
5136a82
improved reading zip and wave files
jessicapriebe Feb 14, 2024
209a4b1
executable LibMatrixKeywordSpotting
jessicapriebe Feb 14, 2024
92ac788
fixed readWaveFiles
jessicapriebe Feb 15, 2024
cb52d50
downloader data for keywordspotting
jessicapriebe Feb 16, 2024
79a7506
tried converting bytearrayinput to audioinputarray
jessicapriebe Feb 16, 2024
882be22
fixed
jessicapriebe Feb 16, 2024
fde0258
fixed
jessicapriebe Feb 16, 2024
73cae32
fixed
jessicapriebe Feb 16, 2024
b91d5e4
delete dir after extracting the data + formatting
jessicapriebe Feb 16, 2024
eaa6fbd
added save to CSV
jessicapriebe Feb 16, 2024
990bd6c
removes debugging prints and added start and finish print for downloa…
jessicapriebe Feb 16, 2024
a2bb648
changed short/double to int
jessicapriebe Feb 17, 2024
75f22cb
added TODO
jessicapriebe Feb 15, 2024
a3f8153
converted bytearrayinputstream to audioinoutstream
jessicapriebe Feb 16, 2024
c03359e
fixed
jessicapriebe Feb 16, 2024
f09e2f8
changed short/double to int
jessicapriebe Feb 17, 2024
005bbcd
removed url
jessicapriebe Feb 17, 2024
5267248
changed logic
jessicapriebe Feb 17, 2024
09356ef
fixed writer
jessicapriebe Feb 17, 2024
5e9e195
merged application_zipstream into application
jessicapriebe Feb 17, 2024
3fc6e4d
added suffix
jessicapriebe Feb 17, 2024
be71987
stft dml
mufwan Feb 12, 2024
b5fe741
stft dml integration
mufwan Feb 13, 2024
2da7ad3
handle zero matrix
mufwan Feb 14, 2024
ed32efc
update stft
mufwan Feb 17, 2024
985643b
branch to merge with application
mufwan Feb 17, 2024
a55190f
moved keywordSpotting.dml to scripts
mufwan Feb 18, 2024
9a2bc99
add shuffle
mufwan Feb 18, 2024
1f8cf4b
restricted to yes and no
jessicapriebe Feb 19, 2024
b3d52ee
addded formatting keyword spotting
jessicapriebe Feb 19, 2024
711b766
without parallelization
mufwan Feb 19, 2024
481e42c
accuracy for application
mufwan Feb 19, 2024
a1ec350
new dir for keywordSpotting.dml and fixed bugs from rebase
mufwan Feb 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,6 @@ scripts/perftest/fed/temp
src/test/scripts/functions/iogen/*.raw
src/test/scripts/functions/pipelines/intermediates/regression/*
src/test/scripts/functions/pipelines/intermediates/classification/*

venv
venv/*
5 changes: 5 additions & 0 deletions fft.dml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
print("hello")
M = matrix("0 18 -15 3", rows=1, cols=4)
[r,i] = fft(M)
print(toString(r))
print(toString(i))
34 changes: 34 additions & 0 deletions scripts/tutorials/keywordSpotting/keywordSpotting.dml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

X = read("tmp/waves.csv", format="csv")
y = read("tmp/labels.csv", format="csv")

Xy = cbind(X, y)
num_col = ncol(Xy)
y_rand = rand(rows=nrow(Xy), cols=1, min=0, max=1, pdf="uniform")
Xy_shuffled = order(target = cbind(Xy, y_rand), by = num_col + 1)
Xy_shuffled = Xy_shuffled[,1:num_col] # Remove the random column
X_shuffled = Xy_shuffled[,1:(num_col-1)] # Features, excluding the last column which is labels
y_shuffled = Xy_shuffled[,num_col] # Labels, the last column

[X_train, X_test, y_train, y_test] = split(X=X_shuffled, Y=y_shuffled, seed= 13)

[X_train_re, X_train_im] = stft(X_train, 4, 2)
[X_test_re, X_test_im] = stft(X_test, 4, 2)

X_train_re_sq = X_train_re^2
X_train_im_sq = X_train_im^2

X_test_re_sq = X_test_re^2
X_test_im_sq = X_test_im^2

sum_X_train_sq = X_train_re_sq + X_train_im_sq
sum_X_test_sq = X_test_re_sq + X_test_im_sq

magnitudes_train = sqrt(sum_X_train_sq)
magnitudes_test = sqrt(sum_X_test_sq)

bias = lm(X=magnitudes_train, y=y_train, reg=1e-1, maxi=10, verbose=TRUE)
predictions = lmPredict(X=magnitudes_test, B=bias, verbose=FALSE)

accuracy = auc(Y=y_test, P=predictions)
print(toString(accuracy))
5 changes: 5 additions & 0 deletions src/main/java/org/apache/sysds/common/Builtins.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ public enum Builtins {
FIT_PIPELINE("fit_pipeline", true),
FIX_INVALID_LENGTHS("fixInvalidLengths", true),
FIX_INVALID_LENGTHS_APPLY("fixInvalidLengthsApply", true),
FFT("fft", false, ReturnType.MULTI_RETURN),
FFT_LINEARIZED("fft_linearized", false, ReturnType.MULTI_RETURN),
FF_TRAIN("ffTrain", true),
FF_PREDICT("ffPredict", true),
FLOOR("floor", false),
Expand All @@ -154,6 +156,8 @@ public enum Builtins {
HOSPITAL_RESIDENCY_MATCH("hospitalResidencyMatch", true),
HYPERBAND("hyperband", true),
IFELSE("ifelse", false),
IFFT("ifft", false, ReturnType.MULTI_RETURN),
IFFT_LINEARIZED("ifft_linearized", false, ReturnType.MULTI_RETURN),
IMG_MIRROR("img_mirror", true),
IMG_MIRROR_LINEARIZED("img_mirror_linearized", true),
IMG_BRIGHTNESS("img_brightness", true),
Expand Down Expand Up @@ -305,6 +309,7 @@ public enum Builtins {
STATSNA("statsNA", true),
STRATSTATS("stratstats", true),
STEPLM("steplm",true, ReturnType.MULTI_RETURN),
STFT("stft", false, ReturnType.MULTI_RETURN),
SQRT("sqrt", false),
SUM("sum", false),
SVD("svd", false, ReturnType.MULTI_RETURN),
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/org/apache/sysds/hops/FunctionOp.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,31 @@ else if ( getFunctionName().equalsIgnoreCase("eigen") ) {
long outputValues = OptimizerUtils.estimateSizeExactSparsity(getOutputs().get(1).getDim1(), 1, 1.0);
return outputVectors+outputValues;
}
else if ( getFunctionName().equalsIgnoreCase("fft") ) {
long outputRe = OptimizerUtils.estimateSizeExactSparsity(getOutputs().get(0).getDim1(), getOutputs().get(0).getDim2(), 1.0);
long outputIm = OptimizerUtils.estimateSizeExactSparsity(getOutputs().get(1).getDim1(), getOutputs().get(1).getDim2(), 1.0);
return outputRe+outputIm;
}
else if ( getFunctionName().equalsIgnoreCase("ifft") ) {
long outputRe = OptimizerUtils.estimateSizeExactSparsity(getOutputs().get(0).getDim1(), getOutputs().get(0).getDim2(), 1.0);
long outputIm = OptimizerUtils.estimateSizeExactSparsity(getOutputs().get(1).getDim1(), getOutputs().get(1).getDim2(), 1.0);
return outputRe+outputIm;
}
else if ( getFunctionName().equalsIgnoreCase("fft_linearized") ) {
long outputRe = OptimizerUtils.estimateSizeExactSparsity(getOutputs().get(0).getDim1(), getOutputs().get(0).getDim2(), 1.0);
long outputIm = OptimizerUtils.estimateSizeExactSparsity(getOutputs().get(1).getDim1(), getOutputs().get(1).getDim2(), 1.0);
return outputRe+outputIm;
}
else if ( getFunctionName().equalsIgnoreCase("ifft_linearized") ) {
long outputRe = OptimizerUtils.estimateSizeExactSparsity(getOutputs().get(0).getDim1(), getOutputs().get(0).getDim2(), 1.0);
long outputIm = OptimizerUtils.estimateSizeExactSparsity(getOutputs().get(1).getDim1(), getOutputs().get(1).getDim2(), 1.0);
return outputRe+outputIm;
}
else if ( getFunctionName().equalsIgnoreCase("stft") ) {
long outputRe = OptimizerUtils.estimateSizeExactSparsity(getOutputs().get(0).getDim1(), getOutputs().get(0).getDim2(), 1.0);
long outputIm = OptimizerUtils.estimateSizeExactSparsity(getOutputs().get(1).getDim1(), getOutputs().get(1).getDim2(), 1.0);
return outputRe+outputIm;
}
else if ( getFunctionName().equalsIgnoreCase("lstm") || getFunctionName().equalsIgnoreCase("lstm_backward") ) {
// TODO: To allow for initial version to always run on the GPU
return 0;
Expand Down Expand Up @@ -250,6 +275,26 @@ else if ( getFunctionName().equalsIgnoreCase("eigen")) {
return OptimizerUtils.estimateSizeExactSparsity(getInput().get(0).getDim1(), getInput().get(0).getDim2(), 1.0)
+ 3*OptimizerUtils.estimateSizeExactSparsity(getInput().get(0).getDim1(), 1, 1.0);
}
else if ( getFunctionName().equalsIgnoreCase("fft") ) {
// 2 matrices of size same as the input
return 2*OptimizerUtils.estimateSizeExactSparsity(getInput().get(0).getDim1(), getInput().get(0).getDim2(), 1.0);
}
else if ( getFunctionName().equalsIgnoreCase("ifft") ) {
// 2 matrices of size same as the input
return 2*OptimizerUtils.estimateSizeExactSparsity(getInput().get(0).getDim1(), getInput().get(0).getDim2(), 1.0);
}
else if ( getFunctionName().equalsIgnoreCase("fft_linearized") ) {
// 2 matrices of size same as the input
return 2*OptimizerUtils.estimateSizeExactSparsity(getInput().get(0).getDim1(), getInput().get(0).getDim2(), 1.0);
}
else if ( getFunctionName().equalsIgnoreCase("ifft_linearized") ) {
// 2 matrices of size same as the input
return 2*OptimizerUtils.estimateSizeExactSparsity(getInput().get(0).getDim1(), getInput().get(0).getDim2(), 1.0);
}
else if ( getFunctionName().equalsIgnoreCase("stft") ) {
// 2 matrices of size same as the input
return 2*OptimizerUtils.estimateSizeExactSparsity(getInput().get(0).getDim1(), getInput().get(0).getDim2(), 1.0);
}
else if (getFunctionName().equalsIgnoreCase("batch_norm2d") || getFunctionName().equalsIgnoreCase("batch_norm2d_backward") ||
getFunctionName().equalsIgnoreCase("batch_norm2d_train") || getFunctionName().equalsIgnoreCase("batch_norm2d_test")) {
return 0;
Expand Down
230 changes: 229 additions & 1 deletion src/main/java/org/apache/sysds/parser/BuiltinFunctionExpression.java
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,230 @@ public void validateExpression(MultiAssignmentStatement stmt, HashMap<String, Da

break;
}
case FFT: {
checkNumParameters(1);
checkMatrixParam(getFirstExpr());

DataIdentifier fftOut1 = (DataIdentifier) getOutputs()[0];
DataIdentifier fftOut2 = (DataIdentifier) getOutputs()[1];

// TODO: Add Validation
// if (getFirstExpr().getOutput().getDim2() != 1 ||
// getFirstExpr().getOutput().getDim2() != 2) {
// raiseValidateError("Eigen Decomposition can only be done on a square matrix.
// Input matrix is rectangular (rows=" + getFirstExpr().getOutput().getDim1() +
// ", cols="+ getFirstExpr().getOutput().getDim2() +")", conditional);
// }

// Output1 - FFT Values
fftOut1.setDataType(DataType.MATRIX);
fftOut1.setValueType(ValueType.FP64);
fftOut1.setDimensions(getFirstExpr().getOutput().getDim1(), getFirstExpr().getOutput().getDim2());
fftOut1.setBlocksize(getFirstExpr().getOutput().getBlocksize());

// Output2 - FFT Vectors
fftOut2.setDataType(DataType.MATRIX);
fftOut2.setValueType(ValueType.FP64);
fftOut2.setDimensions(getFirstExpr().getOutput().getDim1(), getFirstExpr().getOutput().getDim2());
fftOut2.setBlocksize(getFirstExpr().getOutput().getBlocksize());

break;

}
case IFFT: {
Expression expressionTwo = getSecondExpr();
checkNumParameters(getSecondExpr() != null ? 2 : 1);
checkMatrixParam(getFirstExpr());
if (expressionTwo != null)
checkMatrixParam(getSecondExpr());

// setup output properties
DataIdentifier ifftOut1 = (DataIdentifier) getOutputs()[0];
DataIdentifier ifftOut2 = (DataIdentifier) getOutputs()[1];

// TODO: Add Validation
// if (getFirstExpr().getOutput().getDim2() != 1 ||
// getFirstExpr().getOutput().getDim2() != 2) {
// raiseValidateError("Eigen Decomposition can only be done on a square matrix.
// Input matrix is rectangular (rows=" + getFirstExpr().getOutput().getDim1() +
// ", cols="+ getFirstExpr().getOutput().getDim2() +")", conditional);
// }

// Output1 - ifft Values
ifftOut1.setDataType(DataType.MATRIX);
ifftOut1.setValueType(ValueType.FP64);
ifftOut1.setDimensions(getFirstExpr().getOutput().getDim1(), getFirstExpr().getOutput().getDim2());
ifftOut1.setBlocksize(getFirstExpr().getOutput().getBlocksize());

// Output2 - ifft Vectors
ifftOut2.setDataType(DataType.MATRIX);
ifftOut2.setValueType(ValueType.FP64);
ifftOut2.setDimensions(getFirstExpr().getOutput().getDim1(), getFirstExpr().getOutput().getDim2());
ifftOut2.setBlocksize(getFirstExpr().getOutput().getBlocksize());

break;
}
case FFT_LINEARIZED: {

Expression expressionOne = getFirstExpr();
Expression expressionTwo = getSecondExpr();

if (expressionOne == null) {
raiseValidateError("The first argument to " + _opcode + " cannot be null.", false, LanguageErrorCodes.INVALID_PARAMETERS);
}

else if (expressionOne.getOutput() == null || expressionOne.getOutput().getDim1() == 0 || expressionOne.getOutput().getDim2() == 0) {
raiseValidateError("The first argument to " + _opcode + " cannot be an empty matrix.", false, LanguageErrorCodes.INVALID_PARAMETERS);
}

else if (expressionTwo != null) {
raiseValidateError("Too many arguments. This FFT_LINEARIZED implementation is only defined for real inputs.", false, LanguageErrorCodes.INVALID_PARAMETERS);
}

else if (!isPowerOfTwo(expressionOne.getOutput().getDim2())) {
raiseValidateError("This FFT_LINEARIZED implementation is only defined for matrices with columns that are powers of 2.", false, LanguageErrorCodes.INVALID_PARAMETERS);
}

checkNumParameters(1);
checkMatrixParam(getFirstExpr());

// setup output properties
DataIdentifier fftOut1 = (DataIdentifier) getOutputs()[0];
DataIdentifier fftOut2 = (DataIdentifier) getOutputs()[1];

// TODO: Add Validation
// if (getFirstExpr().getOutput().getDim2() != 1 ||
// getFirstExpr().getOutput().getDim2() != 2) {
// raiseValidateError("Eigen Decomposition can only be done on a square matrix.
// Input matrix is rectangular (rows=" + getFirstExpr().getOutput().getDim1() +
// ", cols="+ getFirstExpr().getOutput().getDim2() +")", conditional);
// }

// Output1 - FFT Values
fftOut1.setDataType(DataType.MATRIX);
fftOut1.setValueType(ValueType.FP64);
fftOut1.setDimensions(getFirstExpr().getOutput().getDim1(), getFirstExpr().getOutput().getDim2());
fftOut1.setBlocksize(getFirstExpr().getOutput().getBlocksize());

// Output2 - FFT Vectors
fftOut2.setDataType(DataType.MATRIX);
fftOut2.setValueType(ValueType.FP64);
fftOut2.setDimensions(getFirstExpr().getOutput().getDim1(), getFirstExpr().getOutput().getDim2());
fftOut2.setBlocksize(getFirstExpr().getOutput().getBlocksize());

break;
}
case IFFT_LINEARIZED: {
Expression expressionTwo = getSecondExpr();
Expression expressionOne = getFirstExpr();

if (expressionOne == null) {
raiseValidateError("The first argument to " + _opcode + " cannot be null.", false, LanguageErrorCodes.INVALID_PARAMETERS);
}

else if (expressionOne.getOutput() == null || expressionOne.getOutput().getDim1() == 0 || expressionOne.getOutput().getDim2() == 0) {
raiseValidateError("The first argument to " + _opcode + " cannot be an empty matrix.", false, LanguageErrorCodes.INVALID_PARAMETERS);
}

else if (expressionTwo != null){
if(expressionTwo.getOutput() == null || expressionTwo.getOutput().getDim1() == 0 || expressionTwo.getOutput().getDim2() == 0) {
raiseValidateError("The second argument to " + _opcode + " cannot be an empty matrix. Provide either only a real matrix or a filled real and imaginary one.", false, LanguageErrorCodes.INVALID_PARAMETERS);
}
}

checkNumParameters(expressionTwo != null ? 2 : 1);
checkMatrixParam(expressionOne);
if(expressionTwo != null && expressionOne != null){
checkMatrixParam(expressionTwo);
if(expressionOne.getOutput().getDim1() != expressionTwo.getOutput().getDim1() || expressionOne.getOutput().getDim2() != expressionTwo.getOutput().getDim2())
raiseValidateError("The real and imaginary part of the provided matrix are of different dimensions.", false);
else if (!isPowerOfTwo(expressionTwo.getOutput().getDim2())) {
raiseValidateError("This IFFT_LINEARIZED implementation is only defined for matrices with columns that are powers of 2.", false, LanguageErrorCodes.INVALID_PARAMETERS);
}
}
else if(expressionOne != null){
if (!isPowerOfTwo(expressionOne.getOutput().getDim2())) {
raiseValidateError("This IFFT_LINEARIZED implementation is only defined for matrices with columns that are powers of 2.", false, LanguageErrorCodes.INVALID_PARAMETERS);
}
}


DataIdentifier ifftOut1 = (DataIdentifier) getOutputs()[0];
DataIdentifier ifftOut2 = (DataIdentifier) getOutputs()[1];

// TODO: Add Validation
// if (getFirstExpr().getOutput().getDim2() != 1 ||
// getFirstExpr().getOutput().getDim2() != 2) {
// raiseValidateError("Eigen Decomposition can only be done on a square matrix.
// Input matrix is rectangular (rows=" + getFirstExpr().getOutput().getDim1() +
// ", cols="+ getFirstExpr().getOutput().getDim2() +")", conditional);
// }

// Output1 - ifft Values
ifftOut1.setDataType(DataType.MATRIX);
ifftOut1.setValueType(ValueType.FP64);
ifftOut1.setDimensions(getFirstExpr().getOutput().getDim1(), getFirstExpr().getOutput().getDim2());
ifftOut1.setBlocksize(getFirstExpr().getOutput().getBlocksize());

// Output2 - ifft Vectors
ifftOut2.setDataType(DataType.MATRIX);
ifftOut2.setValueType(ValueType.FP64);
ifftOut2.setDimensions(getFirstExpr().getOutput().getDim1(), getFirstExpr().getOutput().getDim2());
ifftOut2.setBlocksize(getFirstExpr().getOutput().getBlocksize());

break;
}
case STFT:
{
checkMatrixParam(getFirstExpr());

if ((getFirstExpr() == null || getSecondExpr() == null || getThirdExpr() == null) && _args.length > 0) {
raiseValidateError("Missing argument for function " + this.getOpCode(), false,
LanguageErrorCodes.INVALID_PARAMETERS);
} else if (getFifthExpr() != null) {
raiseValidateError("Invalid number of arguments for function " + this.getOpCode().toString().toLowerCase()
+ "(). This function only takes 3 or 4 arguments.", false);
} else if (_args.length == 3) {
checkScalarParam(getSecondExpr());
checkScalarParam(getThirdExpr());
if (!isPowerOfTwo(((ConstIdentifier) getSecondExpr().getOutput()).getLongValue())) {
raiseValidateError("This FFT implementation is only defined for matrices with dimensions that are powers of 2." +
"The window size (2nd argument) is not a power of two", false, LanguageErrorCodes.INVALID_PARAMETERS);
} else if (((ConstIdentifier) getSecondExpr().getOutput()).getLongValue() <= ((ConstIdentifier) getThirdExpr().getOutput()).getLongValue()) {
raiseValidateError("Overlap can't be larger than or equal to the window size.", false, LanguageErrorCodes.INVALID_PARAMETERS);
}
} else if (_args.length == 4) {
checkMatrixParam(getSecondExpr());
checkScalarParam(getThirdExpr());
checkScalarParam(getFourthExpr());
if (!isPowerOfTwo(((ConstIdentifier) getThirdExpr().getOutput()).getLongValue())) {
raiseValidateError("This FFT implementation is only defined for matrices with dimensions that are powers of 2." +
"The window size (3rd argument) is not a power of two", false, LanguageErrorCodes.INVALID_PARAMETERS);
} else if (getFirstExpr().getOutput().getDim1() != getSecondExpr().getOutput().getDim1() || getFirstExpr().getOutput().getDim2() != getSecondExpr().getOutput().getDim2()) {
raiseValidateError("The real and imaginary part of the provided matrix are of different dimensions.", false);
} else if (((ConstIdentifier) getThirdExpr().getOutput()).getLongValue() <= ((ConstIdentifier) getFourthExpr().getOutput()).getLongValue()) {
raiseValidateError("Overlap can't be larger than or equal to the window size.", false, LanguageErrorCodes.INVALID_PARAMETERS);
}
}

// setup output properties
DataIdentifier stftOut1 = (DataIdentifier) getOutputs()[0];
DataIdentifier stftOut2 = (DataIdentifier) getOutputs()[1];

// Output1 - stft Values
stftOut1.setDataType(DataType.MATRIX);
stftOut1.setValueType(ValueType.FP64);
stftOut1.setDimensions(getFirstExpr().getOutput().getDim1(), getFirstExpr().getOutput().getDim2());
stftOut1.setBlocksize(getFirstExpr().getOutput().getBlocksize());

// Output2 - stft Vectors
stftOut2.setDataType(DataType.MATRIX);
stftOut2.setValueType(ValueType.FP64);
stftOut2.setDimensions(getFirstExpr().getOutput().getDim1(), getFirstExpr().getOutput().getDim2());
stftOut2.setBlocksize(getFirstExpr().getOutput().getBlocksize());

break;
}
case REMOVE: {
checkNumParameters(2);
checkListParam(getFirstExpr());
Expand Down Expand Up @@ -439,7 +663,11 @@ public void validateExpression(MultiAssignmentStatement stmt, HashMap<String, Da
raiseValidateError("Unknown Builtin Function opcode: " + _opcode, false);
}
}


private static boolean isPowerOfTwo(long n) {
return (n > 0) && ((n & (n - 1)) == 0);
}

private static void setDimensions(DataIdentifier out, Expression exp) {
out.setDataType(DataType.MATRIX);
out.setValueType(ValueType.FP64);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/apache/sysds/parser/DMLTranslator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2237,6 +2237,11 @@ private Hop processMultipleReturnBuiltinFunctionExpression(BuiltinFunctionExpres
case QR:
case LU:
case EIGEN:
case FFT:
case IFFT:
case FFT_LINEARIZED:
case IFFT_LINEARIZED:
case STFT:
case LSTM:
case LSTM_BACKWARD:
case BATCH_NORM2D:
Expand Down
Loading