Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 8 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,19 @@ let package = Package(
.target(
name: "pocketFFT"
),
.target(
name: "CLAPACKHelper",
dependencies: [
.product(name: "CLAPACK", package: "CLAPACK"),
],
publicHeadersPath: "include"
),
.target(
name: "Matft",
dependencies: [
.product(name: "Collections", package: "swift-collections"),
"pocketFFT",
.product(name: "CLAPACK", package: "CLAPACK", condition: .when(platforms: [.wasi])),
.target(name: "CLAPACKHelper", condition: .when(platforms: [.wasi])),
]),
.testTarget(
name: "MatftTests",
Expand Down
48 changes: 48 additions & 0 deletions Sources/CLAPACKHelper/clapack_helper.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// clapack_helper.c
// Wrapper implementations that call CLAPACK functions with correct void signatures.

#include "include/clapack_helper.h"

// Declare the actual CLAPACK functions with correct void return type
// These are the real signatures from the f2c-generated code
extern void dgetrf_(
clapack_int *m,
clapack_int *n,
double *a,
clapack_int *lda,
clapack_int *ipiv,
clapack_int *info
);

extern void dgetri_(
clapack_int *n,
double *a,
clapack_int *lda,
clapack_int *ipiv,
double *work,
clapack_int *lwork,
clapack_int *info
);

void clapack_dgetrf_wrapper(
clapack_int *m,
clapack_int *n,
double *a,
clapack_int *lda,
clapack_int *ipiv,
clapack_int *info
) {
dgetrf_(m, n, a, lda, ipiv, info);
}

void clapack_dgetri_wrapper(
clapack_int *n,
double *a,
clapack_int *lda,
clapack_int *ipiv,
double *work,
clapack_int *lwork,
clapack_int *info
) {
dgetri_(n, a, lda, ipiv, work, lwork, info);
}
32 changes: 32 additions & 0 deletions Sources/CLAPACKHelper/include/clapack_helper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// clapack_helper.h
// This header provides correct function signatures for CLAPACK functions.
// The CLAPACK header incorrectly declares these as returning int,
// but the actual f2c-generated implementation returns void.

#ifndef CLAPACK_HELPER_H
#define CLAPACK_HELPER_H

// On wasm32, long is 32-bit
typedef long clapack_int;

// Wrapper functions that call CLAPACK with correct void return type
void clapack_dgetrf_wrapper(
clapack_int *m,
clapack_int *n,
double *a,
clapack_int *lda,
clapack_int *ipiv,
clapack_int *info
);

void clapack_dgetri_wrapper(
clapack_int *n,
double *a,
clapack_int *lda,
clapack_int *ipiv,
double *work,
clapack_int *lwork,
clapack_int *info
);

#endif // CLAPACK_HELPER_H
Loading
Loading