Skip to content

Commit

Permalink
fixed proc macro dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
tbetcke committed Mar 16, 2024
1 parent 2f1268d commit 75a76d4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 44 deletions.
43 changes: 3 additions & 40 deletions proc-macro/src/dense.rs
Original file line number Diff line number Diff line change
@@ -1,42 +1,5 @@
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, ItemStruct};

pub(crate) fn rlst_static_size_impl(args: TokenStream, input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as ItemStruct);
let struct_name = input.ident.clone();

let args = args.to_string();

let dims: Vec<&str> = args.split(',').map(|elem| elem.trim()).collect();
let m = dims[0].parse::<usize>().unwrap();
let n = dims[1].parse::<usize>().unwrap();

let output = quote! {
#input

impl rlst_dense::traits::SizeIdentifier for #struct_name {
const SIZE: rlst_dense::traits::SizeIdentifierValue = rlst_dense::traits::SizeIdentifierValue::Static(#m, #n);
}

impl<T: rlst_common::types::Scalar> rlst_dense::traits::MatrixBuilder<T> for #struct_name {
type Out = rlst_dense::GenericBaseMatrix::<T, rlst_dense::ArrayContainer<T, {#m * #n}>, #struct_name>;


fn new_matrix(dim: (usize, usize)) -> Self::Out {

assert_eq!(dim, (#m, #n), "Expected fixed dimension ({}, {}) for static matrix.", #m, #n);
use rlst_dense::LayoutType;
<Self::Out>::from_data(rlst_dense::ArrayContainer::<T, {#m * #n}>::new(),
rlst_dense::DefaultLayout::from_dimension((#m, #n)),
)

}
}

};
output.into()
}

pub(crate) fn rlst_static_array_impl(items: TokenStream) -> TokenStream {
let args = items.to_string();
Expand All @@ -55,8 +18,8 @@ pub(crate) fn rlst_static_array_impl(items: TokenStream) -> TokenStream {
let ndim: usize = dims.iter().product();

let output = quote! { {
let data = rlst_dense::data_container::ArrayContainer::<#ty, #ndim>::new();
rlst_dense::array::Array::new(rlst_dense::base_array::BaseArray::new(data, [#(#dims),*]))
let data = rlst::dense::data_container::ArrayContainer::<#ty, #ndim>::new();
rlst::dense::array::Array::new(rlst_dense::base_array::BaseArray::new(data, [#(#dims),*]))
}
};

Expand All @@ -80,7 +43,7 @@ pub(crate) fn rlst_static_type_impl(items: TokenStream) -> TokenStream {
let nelem: usize = dims.iter().product();
let ndim = args[1..].len();

let output = quote! { rlst_dense::array::Array<#ty, rlst_dense::base_array::BaseArray<#ty, rlst_dense::data_container::ArrayContainer<#ty, #nelem>, #ndim>, #ndim>
let output = quote! { rlst::dense::array::Array<#ty, rlst::dense::base_array::BaseArray<#ty, rlst::dense::data_container::ArrayContainer<#ty, #nelem>, #ndim>, #ndim>
};

output.into()
Expand Down
4 changes: 0 additions & 4 deletions proc-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ use proc_macro::TokenStream;

mod dense;

#[proc_macro_attribute]
pub fn rlst_static_size(args: TokenStream, input: TokenStream) -> TokenStream {
dense::rlst_static_size_impl(args, input)
}
#[proc_macro]
pub fn rlst_static_array(items: TokenStream) -> TokenStream {
dense::rlst_static_array_impl(items)
Expand Down

0 comments on commit 75a76d4

Please sign in to comment.