Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
89fb851
ENH: array api standard for torch cpu
Sep 12, 2026
2321b33
ENH,TST: ensure float, check and convert arrays
Sep 14, 2026
ec6f302
ENH: move_to from private utility funcs
sdtemple Sep 19, 2026
b2b3a03
ENH: activation functions with xp
Sep 21, 2026
412e50e
ENH: zero must be tensor in max func
Sep 21, 2026
1e91625
ENH,TST: array api dtypes, sklearn tags, and fixtures
Sep 24, 2026
7f58164
ENH,TST: sklearn-based tests
Sep 28, 2026
b60d0e7
ENH,TST: array api checks local to some tests
Sep 28, 2026
04297ca
ENH,TST: make_regression test for torch
Sep 29, 2026
b5e1a3c
MAINT: xp.min instead of min or .min()
Sep 29, 2026
d25c9f5
ENH,TST: xp flexible tests for check values
Sep 29, 2026
3fda2d3
ENH,TST,BUG: need with context, atol and rtol control
Sep 29, 2026
20dc3bb
ENH,TST: use yield for namespace, device, dtype
sdtemple Oct 12, 2026
48b8688
ENH: revise for strict Array API
sdtemple Oct 14, 2026
96fd0a2
TST: no check array api for classifier
sdtemple Oct 14, 2026
faf9bbb
CI: CI for array API
sdtemple Oct 19, 2026
368108c
ENH,MAINT: use xp for `sigmoid`, `log_sigmoid`
sdtemple Oct 19, 2026
5551b12
ENH,TST: `partial_fit` for array API
sdtemple Oct 20, 2026
9da78d1
ENH,TST: softmax; tighter atol, rtol bounds for float64
sdtemple Oct 20, 2026
b5deaf9
TST: `sklearn` api compliance already handles array API
sdtemple Oct 20, 2026
ecf9ba1
ENH,TST: revisions after Emma's PR
sdtemple Oct 23, 2026
50f9f4d
TST: `xpx` assert, small `partial_fit` test
sdtemple Oct 26, 2026
cc2847b
ENH: `xp.asarray` in `partial_fit`
sdtemple Oct 26, 2026
0401566
CI: not cuda, xpu, mps for Array API CI
sdtemple Oct 27, 2026
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
38 changes: 38 additions & 0 deletions .github/workflows/array-api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Array API CI

on:
push:
branches:
- maintenance/**
pull_request:
branches:
- main
- maintenance/**

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
python-version: ["3.14"]

steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install -v .
python -m pip install -v --group test
python -m pip install torch array-api-strict array-api-compat
- name: test
run: |
cd $RUNNER_TEMP
SCIPY_ARRAY_API=1 python -m pytest
--pyargs gfdl
--cov=gfdl
--cov-report=term-missing
-k "not (cuda or xpu or mps)"
43 changes: 27 additions & 16 deletions src/gfdl/activations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
Activation functions for Gradient Free Deep Learning estimators.
"""

import numpy as np
import scipy
from sklearn.utils._array_api import get_namespace_and_device


def relu(z):
Expand All @@ -17,10 +16,12 @@ def relu(z):

Returns
-------
numpy.ndarray
array
The output array with only positive values.
"""
return np.maximum(0, z)
xp, _, device = get_namespace_and_device(z)
zero = xp.asarray(0, dtype=z.dtype, device=device)
Comment thread
sdtemple marked this conversation as resolved.
return xp.maximum(zero, z)


def tanh(z):
Expand All @@ -34,14 +35,15 @@ def tanh(z):

Returns
-------
numpy.ndarray
array
The output array with hyperbolic tangent values.

See Also
--------
numpy.tanh : The hyperbolic tangent function.
"""
return np.tanh(z)
xp, _, _device = get_namespace_and_device(z)
return xp.tanh(z)


def sigmoid(z):
Expand All @@ -55,14 +57,15 @@ def sigmoid(z):

Returns
-------
numpy.ndarray
array
The output array with the function values.

See Also
--------
scipy.special.expit : The logistic sigmoid function.
"""
return scipy.special.expit(z)
xp, _, _ = get_namespace_and_device(z)
return xp.exp(-xp.logaddexp(xp.zeros_like(z), -z))


def identity(z):
Expand All @@ -76,7 +79,7 @@ def identity(z):

Returns
-------
numpy.ndarray
array
The input array is returned unchanged.
"""
return z
Expand All @@ -93,14 +96,17 @@ def softmax(z):

Returns
-------
numpy.ndarray
array
The output array with the function values.

See Also
--------
scipy.special.softmax : The softmax function.
"""
return scipy.special.softmax(z, axis=-1)
xp, _, _ = get_namespace_and_device(z)
tmp = z - xp.max(z, axis=1, keepdims=True)
exp_tmp = xp.exp(tmp)
return exp_tmp / xp.sum(exp_tmp, axis=1, keepdims=True)


def softmin(z):
Expand All @@ -116,7 +122,7 @@ def softmin(z):

Returns
-------
numpy.ndarray
array
The output array with the function values.

See Also
Expand All @@ -137,14 +143,15 @@ def log_sigmoid(z):

Returns
-------
numpy.ndarray
array
The output array with the function values.

See Also
--------
scipy.special.log_expit : The logistic sigmoid function.
"""
return scipy.special.log_expit(z)
xp, _, _ = get_namespace_and_device(z)
return -xp.logaddexp(xp.zeros_like(z), -z)


def log_softmax(z):
Expand All @@ -158,14 +165,18 @@ def log_softmax(z):

Returns
-------
numpy.ndarray
array
The output array with the function values.

See Also
--------
scipy.special.log_softmax : The logarithm of softmax function.
"""
return scipy.special.log_softmax(z, axis=-1)
xp, _, _ = get_namespace_and_device(z)
shifted = z - xp.max(z, axis=1, keepdims=True)
return shifted - xp.log(
xp.sum(xp.exp(shifted), axis=1, keepdims=True)
)


ACTIVATIONS = {
Expand Down
Loading
Loading