Source
stdlib/tests/linalg_smoke_test.cpp
1
// Copyright (c) 2026 BigBrain LLC. MIT-licensed (see LICENSE).2
// Original work; see ACKNOWLEDGMENTS.md for the open-source ideas we build upon.3
#include "linalg.hpp"4
#include "ndarray.hpp"6
#include <gtest/gtest.h>8
// Smoke tests for the linear-algebra core, under GoogleTest. Linked against the9
// STATIC library, so a passing run proves libcheatah_linalg.a is usable end to10
// end. Focused behaviours (decompositions, solves, …) live in the routines11
// suite; this file just confirms the library links and its entry points work.13
namespace nd = cheatah::ndarray;14
namespace la = cheatah::linalg;16
TEST(LinalgSmoke, SimdFeaturesReported) {17
EXPECT_FALSE(la::simd_features().empty());18
EXPECT_GE(la::simd_lane_doubles(), 1);19
}21
TEST(LinalgSmoke, SimdScalarFallback) {22
// The no-SIMD fallback (unreachable on this SIMD build) tested directly.23
EXPECT_EQ(la::detail::scalar_if_empty(""), "scalar");24
EXPECT_EQ(la::detail::scalar_if_empty("AVX2;FMA"), "AVX2;FMA");25
}27
TEST(LinalgSmoke, DotMatchesHandComputed) {28
EXPECT_DOUBLE_EQ(la::dot(nd::array({1.0, 2.0, 3.0, 4.0}), nd::array({5.0, 6.0, 7.0, 8.0})), 70.0);29
}31
TEST(LinalgSmoke, MatmulMatchesHandComputed) {32
const nd::NDArray a = nd::reshape(nd::array({1.0, 2.0, 3.0, 4.0, 5.0, 6.0}), {2, 3});33
const nd::NDArray b = nd::reshape(nd::array({7.0, 8.0, 9.0, 10.0, 11.0, 12.0}), {3, 2});34
const nd::NDArray c = la::matmul(a, b); // [[58, 64], [139, 154]]35
EXPECT_DOUBLE_EQ(nd::get(c, {0, 0}), 58.0);36
EXPECT_DOUBLE_EQ(nd::get(c, {1, 1}), 154.0);37
}