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

Transpose sparse matrix #13

Merged
merged 3 commits into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
config:
- {
name: linux,
os: ubuntu-latest,
os: ubuntu-18.04,
cmake_options: '-DCMAKE_CXX_COMPILER=/usr/bin/g++-4.8 -DCMAKE_C_COMPILER=/usr/bin/gcc-4.8',
artifact_name: libmath.so,
artifact_path: linux_64
Expand All @@ -31,7 +31,7 @@ jobs:

steps:
- name: Install pre-requisites
if: matrix.config.os == 'ubuntu-latest'
if: matrix.config.name == 'linux'
run: sudo apt-get install g++-4.8 gcc-4.8 liblapack-dev libblas-dev

- name: Checkout sources
Expand Down
34 changes: 34 additions & 0 deletions src/lu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,40 @@ JNIEXPORT jobject JNICALL Java_com_powsybl_math_matrix_SparseMatrix_times(JNIEnv
return nullptr;
}

/*
* Class: com.powsybl_math_matrix_SparseMatrix
* Method: transpose
* Signature: (II[I[I[D)Lcom/powsybl/math/matrix/SparseMatrix;
*/
JNIEXPORT jobject JNICALL Java_com_powsybl_math_matrix_SparseMatrix_transpose(JNIEnv * env, jobject, jint m, jint n, jintArray j_ap, jintArray j_ai, jdoubleArray j_ax) {
try {
powsybl::jni::IntArray ap(env, j_ap);
powsybl::jni::IntArray ai(env, j_ai);
powsybl::jni::DoubleArray ax(env, j_ax);

cs_di a;
a.nz = -1;
a.nzmax = ax.length();
a.m = m;
a.n = n;
a.p = ap.get();
a.i = ai.get();
a.x = ax.get();

cs_di* at = cs_di_transpose(&a, 1);

powsybl::jni::IntArray apt(env, at->p, at->n + 1);
powsybl::jni::IntArray ait(env, at->i, at->nzmax);
powsybl::jni::DoubleArray axt(env, at->x, at->nzmax);
return powsybl::jni::ComPowsyblMathMatrixSparseMatrix(env, at->m, at->n, apt, ait, axt).obj();
} catch (const std::exception& e) {
powsybl::jni::throwJavaLangRuntimeException(env, e.what());
} catch (...) {
powsybl::jni::throwJavaLangRuntimeException(env, "Unknown exception");
}
return nullptr;
}

#ifdef __cplusplus
}
#endif