File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,18 @@ describe('matrix power', () => {
1111 let x = new Matrix ( 3 , 3 ) ;
1212 expect ( ( ) => x . mpow ( - 2 ) ) . toThrowError ( ) ;
1313 } ) ;
14+ it ( 'Small integer powers' , ( ) => {
15+ let m = new Matrix ( [
16+ [ 1 , 2 ] ,
17+ [ 3 , 4 ] ,
18+ ] ) ;
19+ let mpowByMmul = Matrix . eye ( 2 ) ;
20+ for ( let i = 0 ; i < 10 ; ++ i ) {
21+ expect ( m . mpow ( i ) ) . toStrictEqual ( mpowByMmul ) ;
22+ mpowByMmul = mpowByMmul . mmul ( m ) ;
23+ }
24+ } ) ;
25+
1426 it ( 'A matrix to the power 0 is identity' , ( ) => {
1527 expect (
1628 new Matrix ( [
Original file line number Diff line number Diff line change @@ -885,7 +885,7 @@ export class AbstractMatrix {
885885 let result = Matrix . eye ( this . rows ) ;
886886 let bb = this ;
887887 // Note: Don't bit shift. In JS, that would truncate at 32 bits
888- for ( let e = scalar ; e > 1 ; e /= 2 ) {
888+ for ( let e = scalar ; e >= 1 ; e /= 2 ) {
889889 if ( ( e & 1 ) !== 0 ) {
890890 result = result . mmul ( bb ) ;
891891 }
You can’t perform that action at this time.
0 commit comments