1#![warn(missing_docs)]
28#![warn(clippy::all)]
29#![allow(clippy::module_name_repetitions)]
31#![allow(clippy::similar_names)]
32#![allow(clippy::too_many_lines)]
33#![allow(clippy::too_many_arguments)]
34#![allow(clippy::many_single_char_names)]
35#![allow(clippy::cast_possible_truncation)]
36#![allow(clippy::cast_sign_loss)]
37#![allow(clippy::use_self)]
39#![allow(clippy::items_after_statements)]
41#![allow(clippy::doc_markdown)]
43#![allow(clippy::missing_errors_doc)]
45#![allow(clippy::missing_panics_doc)]
46#![allow(clippy::must_use_candidate)]
48#![allow(clippy::return_self_not_must_use)]
49#![allow(clippy::match_same_arms)]
51#![allow(clippy::needless_lifetimes)]
53#![allow(clippy::needless_range_loop)]
55#![allow(clippy::missing_const_for_fn)]
57#![allow(clippy::unnecessary_wraps)]
59#![allow(clippy::ptr_as_ptr)]
61#![allow(clippy::transmute_ptr_to_ref)]
63#![allow(clippy::cast_possible_wrap)]
65#![allow(clippy::cast_precision_loss)]
66#![allow(clippy::missing_safety_doc)]
68#![allow(clippy::assign_op_pattern)]
70#![allow(clippy::transmute_undefined_repr)]
72#![allow(clippy::missing_transmute_annotations)]
73#![allow(clippy::inline_always)]
75#![allow(clippy::needless_pass_by_ref_mut)]
77#![allow(clippy::trivially_copy_pass_by_ref)]
79#![allow(clippy::needless_pass_by_value)]
80#![allow(clippy::if_same_then_else)]
82#![allow(clippy::branches_sharing_code)]
83#![allow(clippy::float_cmp)]
85#![allow(clippy::manual_div_ceil)]
87#![allow(clippy::manual_memcpy)]
89#![allow(clippy::no_effect_underscore_binding)]
91
92pub mod accuracy;
93pub mod cblas;
94pub mod complex_interleaved;
95pub mod level1;
96pub mod level2;
97pub mod level3;
98pub mod ndtensor;
99pub mod tensor;
100
101pub mod prelude {
103 pub use crate::level1::{asum, axpy, copy, dot, iamax, iamin, nrm2, nrm2_sq, scal, swap};
104 pub use crate::level2::{
105 DiagKind,
106 GemvTrans,
107 HerError,
108 HerUplo,
109 SyrError,
110 SyrUplo,
111 TriangularMode,
112 TriangularSide,
113 TrmvError,
114 TrmvOp,
115 TrmvUplo,
116 gemv,
117 gemv_simple,
118 ger,
119 gerc,
120 her,
121 her_new,
122 syr,
124 syr_new,
125 trmv,
127 trmv_alloc,
128 trsv,
129 trsv_in_place,
130 };
131 pub use crate::level3::{
132 Diag,
133 GemmBlocking,
134 GemmKernel,
135 Her2kError,
136 HerkError,
137 Side,
138 Syr2kError,
139 SyrkError,
140 Trans,
141 TrmmDiag,
142 TrmmError,
143 TrmmSide,
144 TrmmTrans,
145 TrmmUplo,
146 Uplo,
147 gemm,
148 gemm_with_par,
149 her2k,
150 her2k_new,
151 herk,
152 herk_new,
153 syr2k,
154 syr2k_new,
155 syrk,
156 syrk_new,
157 trmm,
159 trmm_in_place,
160 trsm,
161 };
162 pub use crate::ndtensor::{NdTensor, NdTensorError, Order};
163}
164
165#[cfg(test)]
166mod tests {
167 use super::*;
168 use oxiblas_matrix::Mat;
169
170 #[test]
171 fn test_gemm_correctness() {
172 let a: Mat<f64> = Mat::from_rows(&[&[1.0, 2.0, 3.0], &[4.0, 5.0, 6.0], &[7.0, 8.0, 9.0]]);
174
175 let b: Mat<f64> = Mat::from_rows(&[&[9.0, 8.0, 7.0], &[6.0, 5.0, 4.0], &[3.0, 2.0, 1.0]]);
176
177 let mut c: Mat<f64> = Mat::zeros(3, 3);
178
179 level3::gemm(1.0, a.as_ref(), b.as_ref(), 0.0, c.as_mut());
180
181 assert!((c[(0, 0)] - 30.0).abs() < 1e-10);
189 assert!((c[(0, 1)] - 24.0).abs() < 1e-10);
190 assert!((c[(0, 2)] - 18.0).abs() < 1e-10);
191 assert!((c[(1, 0)] - 84.0).abs() < 1e-10);
192 }
193
194 #[test]
195 fn test_gemm_non_square() {
196 let a: Mat<f64> = Mat::filled(10, 20, 1.0);
197 let b: Mat<f64> = Mat::filled(20, 15, 1.0);
198 let mut c: Mat<f64> = Mat::zeros(10, 15);
199
200 level3::gemm(1.0, a.as_ref(), b.as_ref(), 0.0, c.as_mut());
201
202 for i in 0..10 {
204 for j in 0..15 {
205 assert!((c[(i, j)] - 20.0).abs() < 1e-10);
206 }
207 }
208 }
209
210 #[test]
211 fn test_gemm_large() {
212 let n = 128;
213 let a: Mat<f64> = Mat::filled(n, n, 1.0);
214 let b: Mat<f64> = Mat::filled(n, n, 1.0);
215 let mut c: Mat<f64> = Mat::zeros(n, n);
216
217 level3::gemm(1.0, a.as_ref(), b.as_ref(), 0.0, c.as_mut());
218
219 for i in 0..n {
221 for j in 0..n {
222 assert!(
223 (c[(i, j)] - n as f64).abs() < 1e-8,
224 "c[{},{}] = {}, expected {}",
225 i,
226 j,
227 c[(i, j)],
228 n
229 );
230 }
231 }
232 }
233}