How to use RoundMatrix method in wpt

Best JavaScript code snippet using wpt

validation_spec.js

Source: validation_spec.js Github

copy

Full Screen

1/​* globals describe, it, expect */​2import { validateMean, validateCovAndGetSVD } from "multivariate-normal/​validation.js";3import { roundMatrix } from "./​util";4describe("The validation function", () => {5 describe("for the mean", () => {6 it("should return the valud if it's valid", () => {7 expect(validateMean( [], 0 )).toEqual( [] );8 expect(validateMean( [1], 1 )).toEqual( [1] );9 expect(validateMean( [1, 2.3], 2 )).toEqual( [1, 2.3] );10 });11 it("should freeze its argument", () => {12 expect(Object.isFrozen(validateMean( [], 0 ))).toEqual(true);13 expect(Object.isFrozen(validateMean( [1], 1 ))).toEqual(true);14 expect(Object.isFrozen(validateMean( [1, 2.3], 2 ))).toEqual(true);15 });16 it("should check that it's an array", () => {17 expect(() => validateMean(1, 1))18 .toThrowError(Error, "Mean must be an array");19 expect(() => validateMean(undefined, 0))20 .toThrowError(Error, "Mean must be an array");21 });22 it("should check that it's an array of numbers", () => {23 expect(() => validateMean([1, "foo", 3], 3))24 .toThrowError(Error, "Mean must be an array of numbers");25 expect(() => validateMean(undefined, 0))26 .toThrowError(Error, "Mean must be an array");27 });28 it("should check that it's the right length", () => {29 expect(() => validateMean([], 1))30 .toThrowError(Error, "Expected mean to have length 1, but had length 0");31 expect(() => validateMean([1, 2, 3], 2))32 .toThrowError(Error, "Expected mean to have length 2, but had length 3");33 });34 });35 describe("for the covariance matrix", () => {36 it("should return the covariance matrix", () => {37 const { cov } = validateCovAndGetSVD([38 [ 1, 0 ],39 [ 0, 1 ],40 ], 2);41 expect(cov).toEqual([42 [ 1, 0 ],43 [ 0, 1 ],44 ]);45 });46 it("should deep-freeze the covariance matrix", () => {47 const { cov } = validateCovAndGetSVD([48 [ 1, 0 ],49 [ 0, 1 ],50 ], 2);51 expect(Object.isFrozen(cov)).toEqual(true);52 expect(Object.isFrozen(cov[0])).toEqual(true);53 expect(Object.isFrozen(cov[1])).toEqual(true);54 });55 it("should return the SVD for a simple identity matrix", () => {56 const { svd: { u, s, v } } = validateCovAndGetSVD([57 [ 1, 0 ],58 [ 0, 1 ],59 ], 2);60 expect(roundMatrix(u)).toEqual([61 [ -1, 0 ],62 [ 0, -1 ],63 ]);64 expect(roundMatrix(v)).toEqual([65 [ -1, 0 ],66 [ 0, -1 ],67 ]);68 expect(roundMatrix(s)).toEqual([69 1,70 1,71 ]);72 });73 it("should return the SVD for a 2x2 matrix", () => {74 const { svd: { u, s, v } } = validateCovAndGetSVD([75 [ 1, 0.9 ],76 [ 0.9, 1 ],77 ], 2);78 expect(roundMatrix(u)).toEqual([79 [ -0.71, -0.71 ],80 [ -0.71, 0.71 ],81 ]);82 expect(roundMatrix(v)).toEqual([83 [ -0.71, -0.71 ],84 [ -0.71, 0.71 ],85 ]);86 expect(roundMatrix(s)).toEqual([87 1.9,88 0.1,89 ]);90 });91 it("should return the SVD for a 3x3 matrix", () => {92 const { svd: { u, s, v } } = validateCovAndGetSVD([93 [ 1, 0, 0.9 ],94 [ 0, 1, 0 ],95 [ 0.9, 0, 1 ],96 ], 3);97 expect(roundMatrix(u)).toEqual([98 [ -0.71, 0, -0.71 ],99 [ 0, 1, 0 ],100 [ -0.71, 0, 0.71 ],101 ]);102 expect(roundMatrix(v)).toEqual([103 [ -0.71, 0, -0.71 ],104 [ 0, 1, 0 ],105 [ -0.71, 0, 0.71 ],106 ]);107 expect(roundMatrix(s)).toEqual([108 1.9,109 1,110 0.1,111 ]);112 });113 it("should check that it's an array", () => {114 expect(() => validateCovAndGetSVD(1, 1))115 .toThrowError(Error, "Covariance must be an array");116 expect(() => validateCovAndGetSVD(undefined, 0))117 .toThrowError(Error, "Covariance must be an array");118 });119 it("should check that it has the right length", () => {120 expect(() => validateCovAndGetSVD([[1, 2]], 2))121 .toThrowError(Error, "Covariance matrix had 1 rows, but it should be a 2x2 square matrix");122 });123 it("should check that every row is an array", () => {124 expect(() => validateCovAndGetSVD([[1, 2], 2], 2))125 .toThrowError(Error, "Row 1 of covariance matrix was not an array");126 });127 it("should check that every row is the right length", () => {128 expect(() => validateCovAndGetSVD([[1, 2], [2]], 2))129 .toThrowError(Error, "Row 1 of covariance matrix had length 1, but it should have length 2");130 });131 it("should check that every row contains only number", () => {132 expect(() => validateCovAndGetSVD([[1, 2], [2, "x"]], 2))133 .toThrowError(Error, "Row 1 of covariance matrix contained a non-numeric value");134 });135 it("should check that it's positive semidefinite", () => {136 /​/​ more correlated with each other than with themselves137 const cov1 = [[1, 1 + 1e-10], [1 + 1e-10, 1]];138 expect(() => validateCovAndGetSVD(cov1, 2))139 .toThrowError(Error, "Covariance isn't positive semidefinite");140 /​/​ X and Y are correlated, and Y and Z are correlated, but141 /​/​ X and Z aren't correlated142 const cov2 = [143 [1, 0.9, 0.9],144 [0.9, 1, 0],145 [0.9, 0, 1],146 ];147 expect(() => validateCovAndGetSVD(cov2, 3))148 .toThrowError(Error, "Covariance isn't positive semidefinite");149 });150 it("should check that it's symmetric", () => {151 const cov = [152 [1, 0.9],153 [0.8, 1],154 ];155 expect(() => validateCovAndGetSVD(cov, 2))156 .toThrowError(Error, "Covariance isn't symmetric");157 });158 });...

Full Screen

Full Screen

layout.computeMatrix.test.ts

Source: layout.computeMatrix.test.ts Github

copy

Full Screen

1import * as tape from 'tape';2import Layout3D from '@core/​Layout3D';3const ignoredSize = {x: 0, y: 0, z: 0};4const roundMatrix = (matrix: number[]) => matrix.map((entry) => Number(entry.toFixed(5)));5tape('layout.computeMatrix', (suite) => {6 suite.test('identity', (test) => {7 test.deepEqual(8 Layout3D.computeMatrix(Layout3D.createLayoutSpec(), ignoredSize),9 [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],10 'default layout spec produces identity matrix',11 );12 test.end();13 });14 suite.test('translation', (test) => {15 const layoutSpec = Layout3D.createLayoutSpec();16 layoutSpec.translation = {x: 1, y: 2, z: 3};17 test.deepEqual(18 Layout3D.computeMatrix(layoutSpec, ignoredSize),19 [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 2, 3, 1],20 'translation populates fourth column',21 );22 test.end();23 });24 suite.test('rotation', (test) => {25 const layoutSpec = Layout3D.createLayoutSpec();26 layoutSpec.rotation.z = Math.PI /​ 4;27 test.deepEqual(28 Layout3D.computeMatrix(layoutSpec, ignoredSize),29 [30 Math.cos(Math.PI /​ 4), Math.sin(Math.PI /​ 4), 0, 0,31 -Math.sin(Math.PI /​ 4), Math.cos(Math.PI /​ 4), 0, 0,32 0, 0, 1, 0,33 0, 0, 0, 1,34 ],35 'rotation.z produces a normal Euclidean rotation matrix',36 );37 layoutSpec.rotation.x = -Math.PI /​ 4;38 test.deepEqual(39 roundMatrix(Layout3D.computeMatrix(layoutSpec, ignoredSize)),40 roundMatrix([41 Math.cos(Math.PI /​ 4), Math.sin(Math.PI /​ 4), 0, 0,42 -0.5, 0.5, -Math.sin(Math.PI /​ 4), 0,43 -0.5, 0.5, Math.cos(Math.PI /​ 4), 0,44 0, 0, 0, 1,45 ]),46 '3D rotation composes correctly',47 );48 test.end();49 });50 suite.test('shear', (test) => {51 const layoutSpec = Layout3D.createLayoutSpec();52 layoutSpec.shear.xy = 1;53 test.deepEqual(54 Layout3D.computeMatrix(layoutSpec, ignoredSize),55 [1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],56 'shear.xy skews X over Y',57 );58 layoutSpec.shear.xz = 0.5;59 test.deepEqual(60 Layout3D.computeMatrix(layoutSpec, ignoredSize),61 [1, 0, 0, 0, 1, 1, 0, 0, 0.5, 0, 1, 0, 0, 0, 0, 1],62 'shear.xz skews X over Z and composes cleanly',63 );64 layoutSpec.shear.yz = 0.5;65 test.deepEqual(66 Layout3D.computeMatrix(layoutSpec, ignoredSize),67 [1, 0, 0, 0, 1, 1, 0, 0, 1, 0.5, 1, 0, 0, 0, 0, 1],68 'shear.yz skews Y over Z and composes cleanly',69 );70 test.end();71 });72 suite.test('origin', (test) => {73 /​/​ When we pass `true` to createLayoutSpec, we get a default center-origin.74 const layoutSpec = Layout3D.createLayoutSpec(true);75 test.deepEqual(76 Layout3D.computeMatrix(layoutSpec, {x: 100, y: 200, z: 0}),77 [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -50, -100, 0, 1],78 'origin offsets translation proportional to layout size',79 );80 test.end();81 });82 suite.test('scale', (test) => {83 const layoutSpec = Layout3D.createLayoutSpec();84 layoutSpec.scale = {x: 1.1, y: 1.2, z: 1.3};85 test.deepEqual(86 Layout3D.computeMatrix(layoutSpec, ignoredSize),87 [1.1, 0, 0, 0, 0, 1.2, 0, 0, 0, 0, 1.3, 0, 0, 0, 0, 1],88 'scale creates a pure scaling matrix',89 );90 test.end();91 });92 suite.test('offset', (test) => {93 const layoutSpec = Layout3D.createLayoutSpec();94 layoutSpec.offset = {x: 1, y: 2, z: 3};95 test.deepEqual(96 Layout3D.computeMatrix(layoutSpec, ignoredSize),97 [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 2, 3, 1],98 'offset offsets translation',99 );100 test.end();101 });102 suite.test('e2e', (test) => {103 const layoutSpec = Layout3D.createLayoutSpec(true);104 layoutSpec.translation = {x: 1, y: 2, z: 3};105 layoutSpec.rotation.z = Math.PI /​ 4;106 layoutSpec.rotation.x = -Math.PI /​ 4;107 layoutSpec.shear.xy = 1;108 layoutSpec.shear.xz = 0.5;109 layoutSpec.shear.yz = 0.5;110 layoutSpec.scale = {x: 1.1, y: 1.2, z: 1.3};111 layoutSpec.offset = {x: 1, y: 2, z: 3};112 test.deepEqual(113 roundMatrix(Layout3D.computeMatrix(layoutSpec, {x: 100, y: 200, z: 0})),114 roundMatrix([115 0.77782, 0.77782, 0, 0,116 0.24853, 1.44853, -0.84853, 0,117 -0.05576, 1.89424, 0.45962, 0,118 -61.74369, -179.74369, 90.85281, 1,119 ]),120 'computeMatrix composes rotation, then shear, then scale, then origin- and explicit-offset translation',121 );122 test.end();123 });124 suite.end();...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var roundMatrix = wptools.roundMatrix;3var matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]];4var roundedMatrix = roundMatrix(matrix, 2);5console.log(roundedMatrix);6var wptools = require('wptools');7var roundMatrix = wptools.roundMatrix;8var matrix = [[1.111,2.222,3.333,4.444],[5.555,6.666,7.777,8.888],[9.999,10.101,11.111,12.121]];9var roundedMatrix = roundMatrix(matrix, 2);10console.log(roundedMatrix);11var wptools = require('wptools');12var roundMatrix = wptools.roundMatrix;13var matrix = [[1.111,2.222,3.333,4.444],[5.555,6.666,7.777,8.888],[9.999,10.101,11.111,12.121]];14var roundedMatrix = roundMatrix(matrix, 3);15console.log(roundedMatrix);16var wptools = require('wptools');17var roundMatrix = wptools.roundMatrix;

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var roundMatrix = wptools.roundMatrix;3];4console.log(roundMatrix(m, 2));5var wptools = require('wptools');6var roundMatrix = wptools.roundMatrix;7];8console.log(roundMatrix(m, 2));

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2wptools.page('Barack Obama').get(function(err, resp) {3 if (err) {4 console.log(err);5 } else {6 console.log(resp.infobox);7 }8});9var wptools = require('wptools');10wptools.page('Barack Obama').get(function(err, resp) {11 if (err) {12 console.log(err);13 } else {14 console.log(resp.infobox);15 }16});17var wptools = require('wptools');18wptools.page('Barack Obama').get(function(err, resp) {19 if (err) {20 console.log(err);21 } else {22 console.log(resp.infobox);23 }24});25var wptools = require('wptools');26wptools.page('Barack Obama').get(function(err, resp) {27 if (err) {28 console.log(err);29 } else {30 console.log(resp.infobox);31 }32});33var wptools = require('wptools');34wptools.page('Barack Obama').get(function(err, resp) {35 if (err) {36 console.log(err);37 } else {38 console.log(resp.infobox);39 }40});41var wptools = require('wptools');42wptools.page('Barack Obama').get(function(err, resp) {43 if (err) {44 console.log(err);45 } else {46 console.log(resp.infobox);47 }48});49var wptools = require('wptools');50wptools.page('Barack Obama').get(function(err, resp) {51 if (err) {52 console.log(err);53 } else {54 console.log(resp.infobox);55 }56});57var wptools = require('

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wiki-pagetools');2var roundMatrix = wptools.roundMatrix;3var matrix = [[1,2,3],[4,5,6],[7,8,9]];4var wptools = require('wiki-pagetools');5var roundMatrix = wptools.roundMatrix;6var matrix = [[1.123,2.345,3.567],[4.789,5.901,6.234],[7.456,8.678,9.890]];7var wptools = require('wiki-pagetools');8var roundMatrix = wptools.roundMatrix;9var matrix = [[1.123,2.345,3.567],[4.789,5.901,6.234],[7.456,8.678,9.890]];10var wptools = require('wiki-pagetools');11var roundMatrix = wptools.roundMatrix;12var matrix = [[1.123,2.345,3.567],[4.789,5.901,6.234],[7.456,8.678,9.890]];13var wptools = require('wiki-pagetools');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var wm = new wptools.RoundMatrix(4);3wm.set(0,0,1);4wm.set(0,1,2);5wm.set(0,2,3);6wm.set(0,3,4);7wm.set(1,0,5);8wm.set(1,1,6);9wm.set(1,2,7);10wm.set(1,3,8);11wm.set(2,0,9);12wm.set(2,1,10);13wm.set(2,2,11);14wm.set(2,3,12);15wm.set(3,0,13);16wm.set(3,1,14);17wm.set(3,2,15);18wm.set(3,3,16);19console.log(wm.get(0,0));20console.log(wm.get(0,1));21console.log(wm.get(0,2));22console.log(wm.get(0,3));23console.log(wm.get(1,0));24console.log(wm.get(1,1));25console.log(wm.get(1,2));26console.log(wm.get(1,3));27console.log(wm.get(2,0));28console.log(wm.get(2,1));29console.log(wm.get(2,2));30console.log(wm.get(2,3));31console.log(wm.get(3,0));32console.log(wm.get(3,1));33console.log(wm.get(3,2));34console.log(wm.get(3,3));

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var matrix = wptools.roundMatrix(3, 5);3console.log(matrix);4var wptools = require('wptools');5var matrix = wptools.roundMatrix(3, 5, 2);6console.log(matrix);7var wptools = require('wptools');8var matrix = wptools.roundMatrix(3, 5, 2, 10);9console.log(matrix);10var wptools = require('wptools');11var matrix = wptools.roundMatrix(3, 5, 2, 10, 20);12console.log(matrix);13var wptools = require('wptools');14var matrix = wptools.roundMatrix(3, 5, 2, 10, 20, 30);15console.log(matrix);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2wptools.get('Eiffel Tower').then(function(page) {3 return page.roundMatrix();4}).then(function(matrix) {5 console.log(matrix);6});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools.js');2var matrix = wptools.RoundMatrix(3,3);3matrix[0][0] = 1;4matrix[0][1] = 2;5matrix[0][2] = 3;6matrix[1][0] = 4;7matrix[1][1] = 5;8matrix[1][2] = 6;9matrix[2][0] = 7;10matrix[2][1] = 8;11matrix[2][2] = 9;12console.log(matrix);13var wptools = require('wptools.js');14var matrix = wptools.RoundMatrix(3,3);15matrix[0][0] = 1;16matrix[0][1] = 2;17matrix[0][2] = 3;18matrix[1][0] = 4;19matrix[1][1] = 5;20matrix[1][2] = 6;21matrix[2][0] = 7;22matrix[2][1] = 8;23matrix[2][2] = 9;24console.log(matrix);

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

27 Best Website Testing Tools In 2022

Testing is a critical step in any web application development process. However, it can be an overwhelming task if you don’t have the right tools and expertise. A large percentage of websites still launch with errors that frustrate users and negatively affect the overall success of the site. When a website faces failure after launch, it costs time and money to fix.

Your Favorite Dev Browser Has Evolved! The All New LT Browser 2.0

We launched LT Browser in 2020, and we were overwhelmed by the response as it was awarded as the #5 product of the day on the ProductHunt platform. Today, after 74,585 downloads and 7,000 total test runs with an average of 100 test runs each day, the LT Browser has continued to help developers build responsive web designs in a jiffy.

Difference Between Web And Mobile Application Testing

Smartphones have changed the way humans interact with technology. Be it travel, fitness, lifestyle, video games, or even services, it’s all just a few touches away (quite literally so). We only need to look at the growing throngs of smartphone or tablet users vs. desktop users to grasp this reality.

Putting Together a Testing Team

As part of one of my consulting efforts, I worked with a mid-sized company that was looking to move toward a more agile manner of developing software. As with any shift in work style, there is some bewilderment and, for some, considerable anxiety. People are being challenged to leave their comfort zones and embrace a continuously changing, dynamic working environment. And, dare I say it, testing may be the most ‘disturbed’ of the software roles in agile development.

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful