concision_linear/
utils.rs1use crate::params::Biased;
6use nd::{ArrayBase, Axis, Dimension, RawData, RemoveAxis};
7
8pub(crate) fn build_bias<S, D, E, F>(biased: bool, dim: D, builder: F) -> Option<ArrayBase<S, E>>
10where
11 D: RemoveAxis<Smaller = E>,
12 E: Dimension,
13 F: Fn(E) -> ArrayBase<S, E>,
14 S: RawData,
15{
16 if biased {
17 Some(builder(bias_dim::<D, E>(dim)))
18 } else {
19 None
20 }
21}
22
23pub(crate) fn bias_dim<D, E>(dim: D) -> E
24where
25 D: RemoveAxis<Smaller = E>,
26 E: Dimension,
27{
28 if dim.ndim() == 1 {
29 dim.remove_axis(Axis(0))
30 } else {
31 dim.remove_axis(Axis(1))
32 }
33}
34
35pub fn is_biased<K: 'static>() -> bool {
38 use core::any::TypeId;
39 TypeId::of::<K>() == TypeId::of::<Biased>()
40}