Complete reference for the sciencekit Lua 5.4 module (sciencekit_lua 0.5.0), grounded directly in src/lib.rs, src/userdata/builder.rs, src/userdata/model.rs, src/engine/family.rs, src/error.rs, and tests/run.lua.
local sciencekit = require("sciencekit")
require("sciencekit") always returns a plain Lua table (type(sciencekit) == "table"), never a callable proxy.
Export Kind Signature Description
sciencekit.versionstring fieldstringPackage version compiled into the crate ("0.5.0"). Note: this is a string value, not a function.
sciencekit.abi_versionfunction () -> { major: integer, minor: integer, patch: integer }Returns a fresh table carrying SK_FFI_ABI_MAJOR, SK_FFI_ABI_MINOR, and SK_FFI_ABI_PATCH (currently { major = 1, minor = 0, patch = 0 }).
sciencekit.featuresfunction () -> integerReturns the sk_ffi_features() capability bitmask reported by sciencekit_ffi as a 64-bit Lua integer.
sciencekit.live_handlesfunction () -> integerReturns the number of live (not yet closed or garbage-collected) builder and model handles on the calling OS thread.
sciencekit.linear_regressionfunction () -> BuilderAllocates an f64 ordinary least-squares builder userdata (family == "linear-regression").
sciencekit.standard_scalerfunction () -> BuilderAllocates an f64 column-standardization builder userdata (family == "standard-scaler").
sciencekit.loadfunction (path: string) -> ModelLoads a persisted fitted f64 linear-regression model from path (loaded.family == "linear-regression").
C symbol Signature Description
luaopen_sciencekitunsafe extern "C-unwind" fn(*mut lua_State) -> c_intNative Lua 5.4 module entry point used by require("sciencekit") and package.loadlib(path, "luaopen_sciencekit").
Returned by sciencekit.linear_regression() and sciencekit.standard_scaler().
Field Type Values Description
builder.familystring"linear-regression" | "standard-scaler"Estimator family identifier.
builder.dtypestring"f64"Scalar precision (f64 IEEE-754 double).
builder.closedbooleanfalse | truetrue once :close() or __close has released the handle.
All configuration setters mutate the builder in place and return the same builder userdata (self), enabling fluent chaining.
Parameters: enabled: boolean
Supported families: "linear-regression" (raises sciencekit unsupported (4) on "standard-scaler").
Description: Configures whether linear regression fits an intercept term.
Parameters: enabled: boolean
Supported families: "standard-scaler" (raises sciencekit unsupported (4) on "linear-regression").
Description: Configures whether each column is centered by subtracting its training mean.
Parameters: enabled: boolean
Supported families: "standard-scaler" (raises sciencekit unsupported (4) on "linear-regression").
Description: Configures whether each column is divided by its training standard deviation.
Parameters: backend: string | integer
Supported families: "linear-regression", "standard-scaler"
Accepted values:
"faer" or 0
"matrix-multiply" (alias "matrixmultiply") or 1
"ndarray-linalg" (alias "ndarray_linalg") or 2
Errors: Raises sciencekit invalid-argument (3) if given an unknown string, an integer outside 0..2, or any other Lua type.
Parameters:
features: table — non-empty rectangular 1-indexed table of numeric rows (N × D).
targets: table | nil — required when builder.family == "linear-regression" (flat sequence { y1, ..., yN } or column { {y1}, ..., {yN} } with length N); omitted (nil) for "standard-scaler".
Returns: A new fitted Model userdata (model.family == builder.family, model.dtype == "f64"). The builder itself remains open.
Errors: Raises sciencekit shape (2), sciencekit invalid-argument (3), or sciencekit invalid-handle (1).
Description: Releases the underlying SKFfiBuilder handle immediately and marks builder.closed = true. Idempotent: subsequent calls are no-ops returning nil.
Metamethod Output / Behavior
__closeReleases the handle when a local builder <close> = ... variable leaves scope. Idempotent.
__tostring"sciencekit builder (<family>)" when open; "sciencekit builder (<family>) [closed]" when closed.
Returned by builder:fit(...) and sciencekit.load(path).
Field Type Values Description
model.familystring"linear-regression" | "standard-scaler"Estimator family identifier.
model.dtypestring"f64"Scalar precision ("f64").
model.closedbooleanfalse | truetrue once :close() or __close has released the handle.
Parameters: features: table — rectangular N × D table of numbers matching the fitted column count D.
Supported families: "linear-regression" (raises sciencekit unsupported (4) on "standard-scaler").
Returns: Fresh N × 1 Lua table of one-element rows: { { y1 }, { y2 }, ..., { yN } }.
Parameters: features: table — rectangular N × D table of numbers matching the fitted column count D.
Supported families: "standard-scaler" (raises sciencekit unsupported (4) on "linear-regression").
Returns: Fresh N × D Lua table of transformed rows.
Parameters:
features: table — rectangular N × D table of numbers.
targets: table — flat sequence or N × 1 table of rows with length N.
Supported families: "linear-regression" (raises sciencekit unsupported (4) on "standard-scaler").
Returns: Coefficient of determination (R²) as a Lua number (f64).
Parameters: path: string — filesystem path without interior NUL bytes.
Supported families: "linear-regression" (raises sciencekit unsupported (4) on "standard-scaler").
Returns: nil.
Description: Releases the underlying SKFfiModel handle immediately and marks model.closed = true. Idempotent.
Metamethod Output / Behavior
__closeReleases the handle when a local model <close> = ... variable leaves scope. Idempotent.
__tostring"sciencekit model (<family>)" when open; "sciencekit model (<family>) [closed]" when closed.
Runtime error strings always match:
sciencekit <status-name> (<code>): <message>
Status name Code
invalid-handle1
shape2
invalid-argument3
unsupported4
not-fitted5
io6
internal7