feat(linalg): matrix infix ops and # matrix methods
Dispatch +/−/* to the linalg plugin for matrix values, retag for EN/ZH method chains, and expand # matrix with T/simplify/ascii-style methods. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
c0fbe9b182
commit
51bb8767e3
16 files changed
+459
-57
No files matched your search
@@ -349,7 +349,7 @@ impl Expr {
|
||||
pub fn to_value(&self) -> Result<Value, String> {
|
||||
let (rows, cols) = self.shape()?;
|
||||
let mut obj = serde_json::Map::new();
|
||||
obj.insert("_type".into(), json!("linalg_expr"));
|
||||
obj.insert("_type".into(), json!("matrix"));
|
||||
obj.insert("shape".into(), json!([rows.to_json(), cols.to_json()]));
|
||||
obj.insert("ascii".into(), json!(self.ascii()));
|
||||
obj.insert("latex".into(), json!(self.latex()));
|
||||
@@ -421,7 +421,13 @@ impl Expr {
|
||||
pub fn from_value(v: &Value) -> Result<Self, String> {
|
||||
let obj = v
|
||||
.as_object()
|
||||
.ok_or_else(|| "linalg_expr must be a map".to_string())?;
|
||||
.ok_or_else(|| "matrix expr must be a map".to_string())?;
|
||||
// Accept legacy `linalg_expr` and author types `matrix` / `矩阵`.
|
||||
if let Some(t) = obj.get("_type").and_then(|x| x.as_str()) {
|
||||
if !matches!(t, "matrix" | "矩阵" | "linalg_expr" | "linalg_dense") {
|
||||
// still allow untyped maps that have `kind`
|
||||
}
|
||||
}
|
||||
let kind = obj
|
||||
.get("kind")
|
||||
.and_then(|x| x.as_str())
|
||||
|
||||
Reference in new issue
Block a user