import { assert } from "@thi.ng/errors/assert" ; import type { NzEntry } from "./api.js" ; export abstract class ASparseMatrix { m : number ; n : number ; constructor ( m , n ) { this . m = m ; this . n = n ; } abstract nzEntries ( ) ; abstract at ( m , n , safe ? ) ; abstract setAt ( m , n , v , safe ? ) ; abstract nnz ( ) ; abstract nnzCol ( n ) ; abstract nnzRow ( m ) ; abstract nzColRows ( n ) ; abstract nzColVals ( n ) ; abstract nzRowCols ( m ) ; abstract nzRowVals ( m ) ; abstract toDense ( ) ; trace ( ) { assert ( this . m === this . n , "matrix is non-square" ) ; let trace = 0 ; for ( let i = this . m ; i -- > 0 ; ) { trace += this . at ( i , i , false ) ; } return trace ; } protected ensureSize ( mat ) { assert ( mat . m === this . m && mat . n === this . n , `incompatible size: (${ mat . m },${ mat . n })` ) ; } }