-
Notifications
You must be signed in to change notification settings - Fork 0
Add basic LAGraph expression evaluation #2
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| [submodule "vendor/LAGraph"] | ||
| path = vendor/LAGraph | ||
| url = https://github.com/SparseLinearAlgebra/LAGraph.git |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,3 +10,4 @@ egg = "0.10.0" | |
| nom = "7.1" | ||
| expect-test = "1.5.1" | ||
| libc = "0.2.0" | ||
| rand = "0.8" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [files] | ||
| extend-exclude = ["vendor/"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| fn main() { | ||
| println!("cargo:rustc-link-lib=dylib=lagraphx"); | ||
| println!("cargo:rustc-link-search=native=vendor/LAGraph/build/experimental"); | ||
|
|
||
| println!("cargo:rustc-link-lib=dylib=lagraph"); | ||
| println!("cargo:rustc-link-search=native=vendor/LAGraph/build/src"); | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,140 @@ | ||||||||||||||||
| use std::ptr::null_mut; | ||||||||||||||||
|
|
||||||||||||||||
| use crate::graph::Graph; | ||||||||||||||||
| use crate::grb; | ||||||||||||||||
| use crate::plan::Plan; | ||||||||||||||||
|
|
||||||||||||||||
| #[repr(C)] | ||||||||||||||||
| #[derive(Clone)] | ||||||||||||||||
| pub enum RpqMatrixOp { | ||||||||||||||||
| Label, | ||||||||||||||||
| Lor, | ||||||||||||||||
| Concat, | ||||||||||||||||
| Kleene, | ||||||||||||||||
| KleeneL, | ||||||||||||||||
| KleeneR, | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| #[repr(C)] | ||||||||||||||||
| #[derive(Clone)] | ||||||||||||||||
| pub struct RpqMatrixPlan { | ||||||||||||||||
| pub op: RpqMatrixOp, | ||||||||||||||||
| pub lhs: *mut RpqMatrixPlan, | ||||||||||||||||
| pub rhs: *mut RpqMatrixPlan, | ||||||||||||||||
| pub mat: grb::Matrix, | ||||||||||||||||
| pub res_mat: grb::Matrix, | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| #[link(name = "lagraphx")] | ||||||||||||||||
| extern "C" { | ||||||||||||||||
| pub fn LAGraph_Init(msg: *mut libc::c_char) -> libc::c_int; | ||||||||||||||||
| pub fn LAGraph_DestroyRpqMatrixPlan(plan: *mut RpqMatrixPlan); | ||||||||||||||||
| pub fn LAGraph_RPQMatrix( | ||||||||||||||||
| ans: *mut usize, | ||||||||||||||||
| plan: *mut RpqMatrixPlan, | ||||||||||||||||
| msg: *mut libc::c_char, | ||||||||||||||||
| ) -> libc::c_longlong; | ||||||||||||||||
| pub fn LAGraph_RPQMatrix_label( | ||||||||||||||||
| mat: *mut grb::Matrix, | ||||||||||||||||
| x: usize, | ||||||||||||||||
| i: usize, | ||||||||||||||||
| j: usize, | ||||||||||||||||
| ) -> libc::c_longlong; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| #[link(name = "lagraph")] | ||||||||||||||||
| extern "C" { | ||||||||||||||||
| pub fn LAGraph_MMRead( | ||||||||||||||||
| mat: *mut grb::Matrix, | ||||||||||||||||
| f: *mut libc::FILE, | ||||||||||||||||
| msg: *mut libc::c_char, | ||||||||||||||||
| ) -> libc::c_int; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| pub fn eval(graph: &Graph, expr: egg::RecExpr<Plan>) -> Result<usize, String> { | ||||||||||||||||
| let mut plans: Vec<RpqMatrixPlan> = vec![ | ||||||||||||||||
| RpqMatrixPlan { | ||||||||||||||||
| op: RpqMatrixOp::Label, | ||||||||||||||||
| lhs: null_mut(), | ||||||||||||||||
| rhs: null_mut(), | ||||||||||||||||
| mat: grb::Matrix::null(), | ||||||||||||||||
| res_mat: grb::Matrix::null() | ||||||||||||||||
| }; | ||||||||||||||||
| expr.len() | ||||||||||||||||
| ]; | ||||||||||||||||
| expr.items().for_each(|(id, plan)| { | ||||||||||||||||
| let eval_plan = match plan { | ||||||||||||||||
| &Plan::Seq([lhs, rhs]) => RpqMatrixPlan { | ||||||||||||||||
| op: RpqMatrixOp::Concat, | ||||||||||||||||
| lhs: plans.get_mut::<usize>(lhs.into()).unwrap() as *mut RpqMatrixPlan, | ||||||||||||||||
| rhs: plans.get_mut::<usize>(rhs.into()).unwrap() as *mut RpqMatrixPlan, | ||||||||||||||||
| res_mat: grb::Matrix::null(), | ||||||||||||||||
| mat: grb::Matrix::null(), | ||||||||||||||||
| }, | ||||||||||||||||
| &Plan::Alt([lhs, rhs]) => RpqMatrixPlan { | ||||||||||||||||
| op: RpqMatrixOp::Lor, | ||||||||||||||||
| lhs: plans.get_mut::<usize>(lhs.into()).unwrap() as *mut RpqMatrixPlan, | ||||||||||||||||
| rhs: plans.get_mut::<usize>(rhs.into()).unwrap() as *mut RpqMatrixPlan, | ||||||||||||||||
| res_mat: grb::Matrix::null(), | ||||||||||||||||
| mat: grb::Matrix::null(), | ||||||||||||||||
| }, | ||||||||||||||||
| &Plan::Star([lhs]) => RpqMatrixPlan { | ||||||||||||||||
| op: RpqMatrixOp::Kleene, | ||||||||||||||||
| lhs: null_mut(), | ||||||||||||||||
| rhs: plans.get_mut::<usize>(lhs.into()).unwrap() as *mut RpqMatrixPlan, | ||||||||||||||||
| res_mat: grb::Matrix::null(), | ||||||||||||||||
| mat: grb::Matrix::null(), | ||||||||||||||||
| }, | ||||||||||||||||
| &Plan::LStar([lhs, rhs]) => RpqMatrixPlan { | ||||||||||||||||
| op: RpqMatrixOp::KleeneL, | ||||||||||||||||
| lhs: plans.get_mut::<usize>(lhs.into()).unwrap() as *mut RpqMatrixPlan, | ||||||||||||||||
| rhs: plans.get_mut::<usize>(rhs.into()).unwrap() as *mut RpqMatrixPlan, | ||||||||||||||||
| res_mat: grb::Matrix::null(), | ||||||||||||||||
| mat: grb::Matrix::null(), | ||||||||||||||||
| }, | ||||||||||||||||
| &Plan::RStar([lhs, rhs]) => RpqMatrixPlan { | ||||||||||||||||
| op: RpqMatrixOp::KleeneR, | ||||||||||||||||
| lhs: plans.get_mut::<usize>(lhs.into()).unwrap() as *mut RpqMatrixPlan, | ||||||||||||||||
| rhs: plans.get_mut::<usize>(rhs.into()).unwrap() as *mut RpqMatrixPlan, | ||||||||||||||||
| res_mat: grb::Matrix::null(), | ||||||||||||||||
| mat: grb::Matrix::null(), | ||||||||||||||||
| }, | ||||||||||||||||
| Plan::Label(meta) => { | ||||||||||||||||
| let mut mat: grb::Matrix = grb::Matrix(std::ptr::null_mut()); | ||||||||||||||||
| let mat = graph | ||||||||||||||||
| .mats | ||||||||||||||||
| .get(&meta.name) | ||||||||||||||||
| .or({ | ||||||||||||||||
| graph.verts.get(&meta.name).map(|vert_idx| { | ||||||||||||||||
| unsafe { | ||||||||||||||||
| LAGraph_RPQMatrix_label( | ||||||||||||||||
| &mut mat as *mut grb::Matrix, | ||||||||||||||||
| *vert_idx, | ||||||||||||||||
| graph.verts.len(), | ||||||||||||||||
| graph.verts.len(), | ||||||||||||||||
| ); | ||||||||||||||||
| } | ||||||||||||||||
| &mat | ||||||||||||||||
| }) | ||||||||||||||||
| }) | ||||||||||||||||
|
Comment on lines
+107
to
+119
|
||||||||||||||||
| .unwrap() | ||||||||||||||||
| .clone(); | ||||||||||||||||
| RpqMatrixPlan { | ||||||||||||||||
| op: RpqMatrixOp::Label, | ||||||||||||||||
| lhs: null_mut(), | ||||||||||||||||
| rhs: null_mut(), | ||||||||||||||||
| res_mat: grb::Matrix::null(), | ||||||||||||||||
| mat, | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| }; | ||||||||||||||||
| plans[std::convert::Into::<usize>::into(id)] = eval_plan; | ||||||||||||||||
| }); | ||||||||||||||||
| let plan = plans.iter_mut().last().unwrap(); | ||||||||||||||||
| let mut ans: usize = 0; | ||||||||||||||||
| unsafe { | ||||||||||||||||
| LAGraph_RPQMatrix(&mut ans, plan as *mut RpqMatrixPlan, null_mut()); | ||||||||||||||||
| LAGraph_DestroyRpqMatrixPlan(plan); | ||||||||||||||||
|
Comment on lines
+136
to
+137
|
||||||||||||||||
| LAGraph_RPQMatrix(&mut ans, plan as *mut RpqMatrixPlan, null_mut()); | |
| LAGraph_DestroyRpqMatrixPlan(plan); | |
| let status = LAGraph_RPQMatrix(&mut ans, plan as *mut RpqMatrixPlan, null_mut()); | |
| LAGraph_DestroyRpqMatrixPlan(plan); | |
| if status != 0 { | |
| return Err(format!("LAGraph_RPQMatrix failed with error code {}", status)); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable
matis shadowed immediately after declaration. The mutablematon line 103 is never used before being shadowed on line 104, making its initialization pointless. Remove the declaration on line 103 or rename one of the variables.