Best Python code snippet using lisa_python
minify.js
Source:minify.js
...156 // comments according to the two conditions157 return (astNode, comment) => {158 if (159 /** @type {{ extract: ExtractCommentsFunction }} */160 condition.extract(astNode, comment)) {161 const commentText = comment.type === "comment2" ? `/*${comment.value}*/` : `//${comment.value}`; // Don't include duplicate comments162 if (!extractedComments.includes(commentText)) {163 extractedComments.push(commentText);164 }165 }166 return (167 /** @type {{ preserve: ExtractCommentsFunction }} */168 condition.preserve(astNode, comment)169 );170 };171}172/**173 * @param {InternalMinifyOptions} options174 * @returns {InternalMinifyResult}...
routines_2.js
Source:routines_2.js
1function execute_BLAS(stmt){2 if (stmt.fn == 'laff.zerov'){3 assign(stmt.args[0], 0.0000);4 }5 if (stmt.fn == 'laff.onev'){6 assign(stmt.args[0], 1.0000);7 }8 if (stmt.fn == 'laff.copy'){9 copy(stmt.args[0], stmt.args[1]);10 }11 if (stmt.fn == 'laff.scal'){12 scal(stmt.args[0], stmt.args[1], false);13 }14 if (stmt.fn == 'laff.invscal'){15 scal(stmt.args[0], stmt.args[1], true);16 }17 if (stmt.fn == 'laff.add'){18 add(stmt.args[0], stmt.args[1], stmt.args[2]);19 }20 if (stmt.fn == 'laff.dots'){21 dot(stmt.args[0], stmt.args[1], stmt.args[2], true);22 }23 if (stmt.fn == 'laff.dot'){24 dot(stmt.args[0], stmt.args[1], stmt.args[2], false);25 }26 if (stmt.fn == 'laff.axpy'){27 axpy(stmt.args[0], stmt.args[1], stmt.args[2]);28 }29 if (stmt.fn == 'laff.mac'){30 mac(stmt.args[0], stmt.args[1], stmt.args[2]);31 }32 if (stmt.fn == 'laff.ger'){33 ger(stmt.args[0], stmt.args[1], stmt.args[2], stmt.args[3]);34 }35 if (stmt.fn == 'laff.gemv'){36 gemv(stmt.args[0], stmt.args[1], stmt.args[2], stmt.args[3], stmt.args[4], stmt.args[5]);37 }38}39function extract_region(xx){40 var x_op;41 //find operands42 for (var i = 0; i != operands.length; ++i){43 if (operands[i].match(xx.op))44 x_op = i;45 }46 //get region47 return operands[x_op].subregion(xx.subregion);48}49function is_scalar(aa){50 var rtn;51 rtn = (aa.op=='');52 if (!rtn){53 var alpha = extract_region(aa);54 rtn = (alpha.m()== 1 && alpha.n()==1);55 }56 return rtn;57}58function extract_scalar_value(aa){59 var scal = 1;60 if (aa.op== ''){61 //alpha is a constant62 scal = Number(aa.subregion);63 }64 else{65 //alpha is an operand66 var alpha = extract_region(aa);67 scal = Number(alpha.getElementAt(0,0));68 }69 return scal;70}71function assign(xx, val){72 var x = extract_region(xx);73 for (var j = 0; j < x.m(); ++j){74 for (var k = 0; k < x.n(); ++k){75 x.setElementAt(j, k, val);76 }77 }78}79function copy(oprdOld, oprdNew){80 var src_region = extract_region(oprdOld); 81 var dst_region = extract_region(oprdNew); 82 if (src_region.m() == dst_region.m() && 83 src_region.n() == dst_region.n()){ //same shape84 for (var j = 0; j < src_region.m(); ++j){85 for (var k = 0; k < src_region.n(); ++k){86 dst_region.setElementAt(j,k, 87 src_region.getElementAt(j,k));88 }89 }90 }91 92 if (src_region.m() == dst_region.n() && 93 src_region.n() == dst_region.m() ){ //transposed vector94 for (var j = 0; j < dst_region.m(); ++j){95 for (var k = 0; k < dst_region.n(); ++k){96 dst_region.setElementAt(j,k, 97 src_region.getElementAt(k,j));98 }99 }100 }101}102function scal(aa, xx, inv){103 var x_op, scal;104 scal = extract_scalar_value(aa);105 //find operands106 for (var i = 0; i != operands.length; ++i){107 if (operands[i].match(xx.op))108 x_op = i;109 }110 //get region111 var x = operands[x_op].subregion(xx.subregion);112 for (var j = 0; j != x.m(); ++j){113 for (var k = 0; k != x.n(); ++k){114 if (!inv)115 x.setElementAt(j, k, x.getElementAt(j, k) * scal);116 else117 x.setElementAt(j, k, x.getElementAt(j, k) / scal);118 }119 }120}121function add(xx, yy, zz){122 var x = extract_region(xx);123 var y = extract_region(yy);124 var z = extract_region(zz);125 if (x.m() == y.m() &&126 x.n() == y.n() &&127 x.m() == z.m() &&128 x.n() == z.n() ){129 for (var i = 0; i != x.m(); ++i){130 for (var j = 0; j != x.n(); ++j){131 z.setElementAt(i, j, x.getElementAt(i, j) + y.getElementAt(i, j));132 }133 }134 }135}136function dot(xx, yy, aa, add_alpha){137 var x_op, y_op, alpha_op;138 var x = extract_region(xx);139 var y = extract_region(yy);140 var alpha = extract_region(aa);141 var outputVal = 0;142 //check dimensions143 if (x.m() == 1 && y.m()== 1){144 //both row vectors145 for ( var i = 0; i != x.n(); ++i){146 outputVal += 147 Number(x.getElementAt(0,i)) * Number(y.getElementAt(0,i));148 }149 }150 else if (x.n() == 1 && y.m()== 1){151 //x is col vector, y is row vector152 for ( var i = 0; i != x.m(); ++i){153 outputVal += 154 Number(x.getElementAt(i,0)) * Number(y.getElementAt(0,i));155 }156 }157 else if (x.m() == 1 && y.n()== 1){158 //y is col vector, x is row vector159 for ( var i = 0; i != x.n(); ++i){160 outputVal += 161 Number(x.getElementAt(0,i)) * Number(y.getElementAt(i,0));162 }163 }164 else if (x.n() == 1 && y.n()== 1){165 //both col vectors166 for ( var i = 0; i != x.m(); ++i){167 outputVal += 168 Number(x.getElementAt(i,0)) * Number(y.getElementAt(i,0));169 }170 }171 if (add_alpha){172 alpha.setElementAt(0,0, outputVal + alpha.getElementAt(0, 0));173 }174 else{175 alpha.setElementAt(0,0, outputVal);176 }177}178function axpy(aa, xx, yy){179 var scal = extract_scalar_value(aa);180 var x = extract_region(xx);181 var y = extract_region(yy);182 183 //compute184 if (x.m() == 1 && y.m()== 1){185 //both row vectors186 for ( var i = 0; i != x.n(); ++i){187 y.setElementAt(0,i, 188 scal * Number(x.getElementAt(0,i)) 189 + Number(y.getElementAt(0,i)));190 }191 }192 else if (x.n() == 1 && y.m()== 1){193 //y is a row vector, x is a column194 for ( var i = 0; i != x.m(); ++i){195 y.setElementAt(0,i,196 scal * Number(x.getElementAt(i,0))197 + Number(y.getElementAt(0,i)));198 }199 }200 else if (x.m() == 1 && y.n()== 1){201 //x is a row vector, y is a column202 for ( var i = 0; i != x.n(); ++i){203 y.setElementAt(i,0, 204 scal * Number(x.getElementAt(0,i)) 205 + Number(y.getElementAt(i,0)));206 }207 }208 else if (x.n() == 1 && y.n() == 1){209 //both col vectors210 for ( var i = 0; i != x.m(); ++i){211 y.setElementAt(i,0, 212 scal * Number(x.getElementAt(i,0))213 + Number(y.getElementAt(i,0)));214 }215 }216}217function mac(xx, yy, aa){218 var x = extract_region(xx);219 var y = extract_region(yy);220 var alpha = extract_region(aa);221 if (x.m() == 1 && y.m() == 1 &&222 x.n() == 1 && y.n() == 1 &&223 alpha.m() == 1 && alpha.n() == 1){224 //everything is a scalar 225 alpha.setElementAt(0, 0, x.getElementAt(0,0) + y.getElementAt(0,0));226 }227}228function ger(aa, xx, yy, CC){229 var scal = extract_scalar_value(aa);230 var x = extract_region(xx);231 var y = extract_region(yy);232 var C = extract_region(CC);233 if (x.m() == C.m() && y.n() == C.n() &&234 x.n() == 1 && y.m() == 1){235 236 for (var i = 0; i != C.m(); ++i){237 for (var j = 0; j != C.n(); ++j){238 C.setElementAt(i, j,239 C.getElementAt(i,j) + scal * x.getElementAt(i,0)*y.getElementAt(0,j));240 }241 }242 }243}244function gemv(tt, aa, AA, xx, bb, yy){245 var alpha = extract_scalar_value(aa);246 var beta = extract_scalar_value(bb);247 248 var A = extract_region(AA);249 var x = extract_region(xx);250 var y = extract_region(yy);251 252 var trans = (tt.subregion != "'Notranspose'");253 var tmp = 0;254 if (!trans){ //y = alpha Ax + beta y255 //x and y are both column vectors256 if (x.n()==1 && y.n()==1){257 for (var i = 0; i != A.m(); ++i){258 tmp = 0;259 for (var j = 0; j != A.n(); ++j){260 tmp += A.getElementAt(i, j) * x.getElementAt(j, 0);261 }262 y.setElementAt(i,0, 263 alpha * tmp + beta * y.getElementAt(i,0));264 }265 }266 //x and y are both row vectors267 //x is a column and y is a row268 //y is a column and x is a row269 }270 else{ //y = alpha A'x + beta y271 //x and y are both row vectors272 if (x.m()==1 && y.m()==1){273 for (var i = 0; i != A.n(); ++i){274 tmp = 0;275 for (var j = 0; j != A.m(); ++j){276 tmp += A.getElementAt(j,i) * x.getElementAt(0,j);277 }278 y.setElementAt(0, i,279 alpha * tmp + beta * y.getElementAt(0, i));280 }281 }282 } ...
index.d.ts
Source:index.d.ts
1export default TerserPlugin;2export type ExtractedCommentsInfo = {3 extractedCommentsSource: import("webpack").sources.RawSource;4 commentsFilename: string;5};6export type Schema = import("schema-utils/declarations/validate").Schema;7export type Compiler = import("webpack").Compiler;8export type Compilation = import("webpack").Compilation;9export type WebpackError = import("webpack").WebpackError;10export type Asset = import("webpack").Asset;11export type TerserECMA = import("terser").ECMA;12export type TerserMinifyOptions = import("terser").MinifyOptions;13export type JestWorker = import("jest-worker").default;14export type RawSourceMap = import("source-map").RawSourceMap;15export type InternalMinifyOptions = import("./minify.js").InternalMinifyOptions;16export type InternalMinifyResult = import("./minify.js").InternalMinifyResult;17export type CustomMinifyOptions = import("./minify.js").CustomMinifyOptions;18export type Rule = RegExp | string;19export type Rules = Rule[] | Rule;20export type MinifyWorker = MinifyWorker;21export type ExtractCommentsFunction = (22 astNode: any,23 comment: {24 value: string;25 type: "comment1" | "comment2" | "comment3" | "comment4";26 pos: number;27 line: number;28 col: number;29 }30) => boolean;31export type ExtractCommentsCondition =32 | boolean33 | string34 | RegExp35 | ExtractCommentsFunction;36export type ExtractCommentsFilename = string | ((fileData: any) => string);37export type ExtractCommentsBanner =38 | string39 | boolean40 | ((commentsFile: string) => string);41export type ExtractCommentsObject = {42 condition: ExtractCommentsCondition;43 filename: ExtractCommentsFilename;44 banner: ExtractCommentsBanner;45};46export type CustomMinifyFunction = (47 fileAndCode: {48 [file: string]: string;49 },50 sourceMap?: import("source-map").RawSourceMap | undefined,51 minifyOptions: any52) => any;53export type ExtractCommentsOptions =54 | ExtractCommentsCondition55 | ExtractCommentsObject;56export type PluginWithTerserOptions = {57 test?: Rules | undefined;58 include?: Rules | undefined;59 exclude?: Rules | undefined;60 terserOptions?: import("terser").MinifyOptions | undefined;61 extractComments?: ExtractCommentsOptions | undefined;62 parallel?: boolean | undefined;63 minify?: CustomMinifyFunction | undefined;64};65export type PluginWithCustomMinifyOptions = {66 test?: Rules | undefined;67 include?: Rules | undefined;68 exclude?: Rules | undefined;69 terserOptions?: any;70 extractComments?: ExtractCommentsOptions | undefined;71 parallel?: boolean | undefined;72 minify?: CustomMinifyFunction | undefined;73};74export type TerserPluginOptions =75 | PluginWithTerserOptions76 | PluginWithCustomMinifyOptions;77/** @typedef {import("schema-utils/declarations/validate").Schema} Schema */78/** @typedef {import("webpack").Compiler} Compiler */79/** @typedef {import("webpack").Compilation} Compilation */80/** @typedef {import("webpack").WebpackError} WebpackError */81/** @typedef {import("webpack").Asset} Asset */82/** @typedef {import("terser").ECMA} TerserECMA */83/** @typedef {import("terser").MinifyOptions} TerserMinifyOptions */84/** @typedef {import("jest-worker").default} JestWorker */85/** @typedef {import("source-map").RawSourceMap} RawSourceMap */86/** @typedef {import("./minify.js").InternalMinifyOptions} InternalMinifyOptions */87/** @typedef {import("./minify.js").InternalMinifyResult} InternalMinifyResult */88/** @typedef {import("./minify.js").CustomMinifyOptions} CustomMinifyOptions */89/** @typedef {RegExp | string} Rule */90/** @typedef {Rule[] | Rule} Rules */91/** @typedef {JestWorker & { transform: (options: string) => InternalMinifyResult, minify: (options: InternalMinifyOptions) => InternalMinifyResult }} MinifyWorker */92/**93 * @callback ExtractCommentsFunction94 * @param {any} astNode95 * @param {{ value: string, type: 'comment1' | 'comment2' | 'comment3' | 'comment4', pos: number, line: number, col: number }} comment96 * @returns {boolean}97 */98/**99 * @typedef {boolean | string | RegExp | ExtractCommentsFunction} ExtractCommentsCondition100 */101/**102 * @typedef {string | ((fileData: any) => string)} ExtractCommentsFilename103 */104/**105 * @typedef {boolean | string | ((commentsFile: string) => string)} ExtractCommentsBanner106 */107/**108 * @typedef {Object} ExtractCommentsObject109 * @property {ExtractCommentsCondition} condition110 * @property {ExtractCommentsFilename} filename111 * @property {ExtractCommentsBanner} banner112 */113/**114 * @callback CustomMinifyFunction115 * @param {{ [file: string]: string }} fileAndCode116 * @param {RawSourceMap} [sourceMap]117 * @param {Object.<any, any>} minifyOptions118 */119/**120 * @typedef {ExtractCommentsCondition | ExtractCommentsObject} ExtractCommentsOptions121 */122/**123 * @typedef {Object} PluginWithTerserOptions124 * @property {Rules} [test]125 * @property {Rules} [include]126 * @property {Rules} [exclude]127 * @property {TerserMinifyOptions} [terserOptions]128 * @property {ExtractCommentsOptions} [extractComments]129 * @property {boolean} [parallel]130 * @property {CustomMinifyFunction} [minify]131 */132/**133 * @typedef {Object} PluginWithCustomMinifyOptions134 * @property {Rules} [test]135 * @property {Rules} [include]136 * @property {Rules} [exclude]137 * @property {Object.<any, any>} [terserOptions]138 * @property {ExtractCommentsOptions} [extractComments]139 * @property {boolean} [parallel]140 * @property {CustomMinifyFunction} [minify]141 */142/**143 * @typedef {PluginWithTerserOptions | PluginWithCustomMinifyOptions} TerserPluginOptions144 */145declare class TerserPlugin {146 /**147 * @private148 * @param {any} input149 * @returns {boolean}150 */151 private static isSourceMap;152 /**153 * @private154 * @param {Error & { line: number, col: number}} error155 * @param {string} file156 * @param {Compilation["requestShortener"]} [requestShortener]157 * @param {SourceMapConsumer} [sourceMap]158 * @returns {Error}159 */160 private static buildError;161 /**162 * @private163 * @param {boolean} parallel164 * @returns {number}165 */166 private static getAvailableNumberOfCores;167 /**168 * @private169 * @param {any} environment170 * @returns {TerserECMA}171 */172 private static getEcmaVersion;173 /**174 * @param {TerserPluginOptions} options175 */176 constructor(options?: TerserPluginOptions);177 options: {178 test: Rules;179 extractComments: ExtractCommentsOptions;180 parallel: boolean;181 include: Rules | undefined;182 exclude: Rules | undefined;183 minify: CustomMinifyFunction | undefined;184 terserOptions: any;185 };186 /**187 * @param {Compiler} compiler188 * @param {Compilation} compilation189 * @param {Record<string, import("webpack").sources.Source>} assets190 * @param {{availableNumberOfCores: number}} optimizeOptions191 * @returns {Promise<void>}192 */193 optimize(194 compiler: Compiler,195 compilation: Compilation,196 assets: Record<string, import("webpack").sources.Source>,197 optimizeOptions: {198 availableNumberOfCores: number;199 }200 ): Promise<void>;201 /**202 * @param {Compiler} compiler203 * @returns {void}204 */205 apply(compiler: Compiler): void;...
test.py
Source:test.py
1import scrapy2class Crawling(scrapy.Spider):3 name = 'test'4 start_urls = ['https://xoso.com.vn']5 def parse(self,response):6 joke = response.xpath("//div[@class='section-content']")7 yield {8 'special-prize': joke.xpath(".//span[@class='special-prize']/text()").extract_first(),9 'prize1': joke.xpath(".//span[@class='prize1']/text()").extract_first(),10 'prize2_item0': joke.xpath(".//span[@id='mb_prize2_item0']/text()").extract_first(),11 'prize2_item1': joke.xpath(".//span[@id='mb_prize2_item1']/text()").extract_first(),12 'prize3_item0': joke.xpath(".//span[@id='mb_prize3_item0']/text()").extract_first(),13 'prize3_item1': joke.xpath(".//span[@id='mb_prize3_item1']/text()").extract_first(),14 'prize3_item2': joke.xpath(".//span[@id='mb_prize3_item2']/text()").extract_first(),15 'prize3_item3': joke.xpath(".//span[@id='mb_prize3_item3']/text()").extract_first(),16 'prize3_item4': joke.xpath(".//span[@id='mb_prize3_item4']/text()").extract_first(),17 'prize3_item5': joke.xpath(".//span[@id='mb_prize3_item5']/text()").extract_first(),18 'prize4_item0': joke.xpath(".//span[@id='mb_prize4_item0']/text()").extract_first(),19 'prize4_item1': joke.xpath(".//span[@id='mb_prize4_item1']/text()").extract_first(),20 'prize4_item2': joke.xpath(".//span[@id='mb_prize4_item2']/text()").extract_first(),21 'prize4_item3': joke.xpath(".//span[@id='mb_prize4_item3']/text()").extract_first(),22 'prize5_item0': joke.xpath(".//span[@id='mb_prize5_item0']/text()").extract_first(),23 'prize5_item1': joke.xpath(".//span[@id='mb_prize5_item1']/text()").extract_first(),24 'prize5_item2': joke.xpath(".//span[@id='mb_prize5_item2']/text()").extract_first(),25 'prize5_item3': joke.xpath(".//span[@id='mb_prize5_item3']/text()").extract_first(),26 'prize5_item4': joke.xpath(".//span[@id='mb_prize5_item4']/text()").extract_first(),27 'prize5_item5': joke.xpath(".//span[@id='mb_prize5_item5']/text()").extract_first(),28 'prize6_item0': joke.xpath(".//span[@id='mb_prize6_item0']/text()").extract_first(),29 'prize6_item1': joke.xpath(".//span[@id='mb_prize6_item1']/text()").extract_first(),30 'prize6_item2': joke.xpath(".//span[@id='mb_prize6_item2']/text()").extract_first(),31 'prize7_item0': joke.xpath(".//span[@id='mb_prize7_item0']/text()").extract_first(),32 'prize7_item1': joke.xpath(".//span[@id='mb_prize7_item1']/text()").extract_first(),33 'prize7_item2': joke.xpath(".//span[@id='mb_prize7_item2']/text()").extract_first(),34 'prize7_item3': joke.xpath(".//span[@id='mb_prize7_item3']/text()").extract_first()...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!