-
-
Notifications
You must be signed in to change notification settings - Fork 9
Feat: Adding Linear Algebra Dot operation support #116
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
bc333df
interfacing with qblas
SwayamInSync babaa96
adding test cases
SwayamInSync c3aaa05
test-1: ci
SwayamInSync ca7dd6d
fixing ci
SwayamInSync 04314e3
fixing ci
SwayamInSync 037021a
fixing ci
SwayamInSync d6fc9c6
fixing linux CI
SwayamInSync f99f565
fixing linux CI
SwayamInSync fb3579c
fixing linux CI
SwayamInSync 03e9acd
fixing linux CI
SwayamInSync 1ed7bab
fixing linux CI
SwayamInSync 63a355e
fixing linux CI
SwayamInSync 88a98d1
fixing linux CI
SwayamInSync 764fc72
updating qblas:
SwayamInSync 1669e5f
fixing macos CI
SwayamInSync b35bac3
bumping macos deployment target
SwayamInSync 042b25a
bumping macos deployment target
SwayamInSync f78dd90
dynamic macos deployment target
SwayamInSync cd88de0
explicit init of res array in dot-mat-mat
SwayamInSync abf0224
fixing windows CI
SwayamInSync c5198d1
disabling qblas for windows; MSVC incompatibility
SwayamInSync c0d93f8
updating CI triggering paths
SwayamInSync 838adee
updating CI triggering paths
SwayamInSync 433aa90
reverting branch to main
SwayamInSync 5836505
bumping qblas
SwayamInSync 33b48fe
umath refactor
SwayamInSync a35abce
updaing ci
SwayamInSync 8516544
switching to apt
SwayamInSync 335f425
submodule fix
SwayamInSync 85e7840
submodule fix
SwayamInSync e467f4b
submodule fix
SwayamInSync e201b90
initial matmul ufunc setup
SwayamInSync 09918a3
mid-way test
SwayamInSync 70ca644
shifting to matmul ufunc
SwayamInSync f89c2e6
will figure out later
SwayamInSync 894a84d
matmul registered with naive
SwayamInSync 6800a90
adding initial qblas support to matmul ufunc, something is breaking, nan
SwayamInSync 742ce64
matmul ufunc completed, naive plugged, qblas experimental
SwayamInSync d993bc9
adding release tracker to keep record for tasks, v1.0.0
SwayamInSync c518a29
it should be failing but passes on x86-64
SwayamInSync bbce2ac
ahh stupid me :), fallback to naive for MSVC
SwayamInSync 5e5fa65
switching to internal function use only
SwayamInSync cec5ace
this should fix them all
SwayamInSync 1fe6c81
wrapping up
SwayamInSync 8f16b99
updated branch to main
SwayamInSync 238ef89
Merge pull request #2 from SwayamInSync/matmul-ufunc
SwayamInSync ed47e33
added test coverage in release_tracker.md
SwayamInSync 573eb76
more edge tests
SwayamInSync c795ef3
adding windows instructions and some small refactor as per reviews
SwayamInSync 07a16c0
rename utils
SwayamInSync File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SwayamInSync marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
from numpy_quaddtype import QuadPrecision, QuadPrecDType | ||
import numpy as np | ||
|
||
def assert_quad_equal(a, b, rtol=1e-15, atol=1e-15): | ||
"""Assert two quad precision values are equal within tolerance""" | ||
# Ensure both operands are QuadPrecision objects for the comparison | ||
if not isinstance(a, QuadPrecision): | ||
a = QuadPrecision(str(a), backend='sleef') | ||
if not isinstance(b, QuadPrecision): | ||
b = QuadPrecision(str(b), backend='sleef') | ||
|
||
# Use quad-precision arithmetic to calculate the difference | ||
diff = abs(a - b) | ||
tolerance = QuadPrecision(str(atol), backend='sleef') + QuadPrecision(str(rtol), backend='sleef') * max(abs(a), abs(b)) | ||
|
||
# Assert using quad-precision objects | ||
assert diff <= tolerance, f"Values not equal: {a} != {b} (diff: {diff}, tol: {tolerance})" | ||
|
||
|
||
def assert_quad_array_equal(a, b, rtol=1e-25, atol=1e-25): | ||
"""Assert two quad precision arrays are equal within tolerance""" | ||
assert a.shape == b.shape, f"Shapes don't match: {a.shape} vs {b.shape}" | ||
|
||
flat_a = a.flatten() | ||
flat_b = b.flatten() | ||
|
||
for i, (val_a, val_b) in enumerate(zip(flat_a, flat_b)): | ||
try: | ||
assert_quad_equal(val_a, val_b, rtol, atol) | ||
except AssertionError as e: | ||
raise AssertionError(f"Arrays differ at index {i}: {e}") | ||
|
||
|
||
def create_quad_array(values, shape=None): | ||
"""Create a QuadPrecision array from values using Sleef backend""" | ||
dtype = QuadPrecDType(backend='sleef') | ||
|
||
if isinstance(values, (list, tuple)): | ||
if shape is None: | ||
# 1D array | ||
quad_values = [QuadPrecision(str(float(v)), backend='sleef') for v in values] | ||
return np.array(quad_values, dtype=dtype) | ||
else: | ||
# Reshape to specified shape | ||
if len(shape) == 1: | ||
quad_values = [QuadPrecision(str(float(v)), backend='sleef') for v in values] | ||
return np.array(quad_values, dtype=dtype) | ||
elif len(shape) == 2: | ||
m, n = shape | ||
assert len(values) == m * n, f"Values length {len(values)} doesn't match shape {shape}" | ||
quad_matrix = [] | ||
for i in range(m): | ||
row = [QuadPrecision(str(float(values[i * n + j])), backend='sleef') for j in range(n)] | ||
quad_matrix.append(row) | ||
return np.array(quad_matrix, dtype=dtype) | ||
|
||
raise ValueError("Unsupported values or shape") | ||
|
||
|
||
def is_special_value(val): | ||
"""Check if a value is NaN or infinite""" | ||
try: | ||
float_val = float(val) | ||
return np.isnan(float_val) or np.isinf(float_val) | ||
except: | ||
return False | ||
|
||
|
||
def arrays_equal_with_nan(a, b, rtol=1e-15, atol=1e-15): | ||
"""Compare arrays that may contain NaN values""" | ||
if a.shape != b.shape: | ||
return False | ||
|
||
flat_a = a.flatten() | ||
flat_b = b.flatten() | ||
|
||
for i, (val_a, val_b) in enumerate(zip(flat_a, flat_b)): | ||
# Handle NaN cases | ||
if is_special_value(val_a) and is_special_value(val_b): | ||
float_a = float(val_a) | ||
float_b = float(val_b) | ||
# Both NaN | ||
if np.isnan(float_a) and np.isnan(float_b): | ||
continue | ||
# Both infinite with same sign | ||
elif np.isinf(float_a) and np.isinf(float_b) and np.sign(float_a) == np.sign(float_b): | ||
continue | ||
else: | ||
return False | ||
elif is_special_value(val_a) or is_special_value(val_b): | ||
return False | ||
else: | ||
try: | ||
assert_quad_equal(val_a, val_b, rtol, atol) | ||
except AssertionError: | ||
return False | ||
|
||
return True |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.