From 95aebd1e1150a77ea6455db71391b55dc3879e67 Mon Sep 17 00:00:00 2001 From: Serge Stinckwich Date: Sat, 25 Jan 2020 16:52:25 +0100 Subject: [PATCH] Release PolyMath v1.0.2 (#165) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [skip CI] * [skip CI] * [skip CI] typos * [skip CI] * Update SMark to 1.0.3 * Update README.md * [Issue 152] Remove Magic From 'initialize' Methods (#153) * [issue-152] Improved code formatting. * [issue-152] Removed some reflection magic so that the code is easier to understand. * [issue-152] Improved code formatting. * Cleanup to load in PharoGs (#150) * Do not use an inst variable name as an argument * Don't use 'p' and 'q' as method temps They are defined as instance variables in the class. If they are not supposed to modify the instance variable, then they should have different names. * Don't begin a block with a dot GemStone isn't happy with empty statements. * Cleanup of Array constructors While legal syntax, GemStone has trouble parsing these. * Don't use instance var name as method argument * Add spacing to clarify when number ends GemStone doesn't like '11do:' as a number since 'd' is a legal exponent. * Spacing to clarify separation of statements * Fix typo with extra space. * [issue-154] Corrected the behaviour of findKey to return 'AllTheRest' when selector has no corresponding initialize message. (#155) * [issue-154] Corrected the behaviour of findKey, making it more testable in the subclass to mitigate risk. * [issue-154] Promoted the local variables in the test to state variable to remove duplication. * [issue-154] Extracted duplicate code to a custom assertion. * [skip CI] * [skip CI] * Create FUNDING.yml * Update FUNDING.yml * Remove curly braces, replaced with Arrays in most cases, should close #159 (#162) * Update dependencies to load from github, should close #160 (#161) * [Issue 154] Refactor PMAccuracy testDataTree method (#163) * [issue-154] Moved the test method to its own test case class so that we can break up the long test method and understand the message better. * [issue-154] Moved some test code to an intention-revealing test method & identified a possible smell. * [issue-154] Moved a block of code to its own intention-revealing test method. * [issue-154] Moved some test code to its own intention-revealing method. * [issue-154] Added a smell comment to help the next developer. * [issue-154] Added more smells to the smell comment. * [issue-154] Moved the test code to an intention-revealing test method, extracted the expected result to a role-revealing local variable. * [issue-154] Extracted test code to its own intention-revealing test method, with a comment identifying a coincidence between expected outcome and a default I discovered in the initialize method. * [issue-154] Added calls to the super class methods as required. * [issue-154] Put the call to the super class method in the right place. * [issue-154] Improved the name of the local variable. We still don't know the role it plays in the test yet so gave it a structural name. * [issue-154] Improved the name of a local variable. * [issue-154] Moved the test code to its own better named test method. * Update .travis.yml * Update appveyor.yml * Fix some of the red tests for Pharo 8 (#164) * Update appveyor.yml * Move from Pharo 7.0 to Pharo 8.0 * Update README.md Co-authored-by: Hemal Varambhia Co-authored-by: James Foster Co-authored-by: Julian Maestri --- .travis.yml | 3 +- CONTRIBUTING.md | 4 +- FUNDING.yml | 1 + README.md | 10 +- appveyor.yml | 2 +- .../BaselineOfPolyMath.class.st | 14 +- .../ExtendedNumberParser.class.st | 2 +- src/Math-Accuracy-Core/PMAccuracy.class.st | 8 +- .../PMODEBenchmark.class.st | 2 +- src/Math-Core-Process/PMFixpoint.class.st | 6 +- src/Math-Core/PMVector.class.st | 2 +- .../PMFastFourierTransform.class.st | 4 +- .../PMAnotherGeneticOptimizer.class.st | 10 +- .../PMGeneralFunctionFit.class.st | 8 +- src/Math-KDTree/PMIndexedKDTree.class.st | 8 +- src/Math-KDTree/PMKDTree.class.st | 2 +- src/Math-KDTree/PMNNStore.class.st | 4 +- .../PMKolmogorovSmirnov2Sample.class.st | 29 +--- src/Math-Matrix/PMMatrix.class.st | 6 +- src/Math-ODE/PMAB2Solver.class.st | 2 +- src/Math-ODE/PMAB3Solver.class.st | 2 +- src/Math-ODE/PMAB4Solver.class.st | 2 +- src/Math-ODE/PMAM3Solver.class.st | 2 +- src/Math-ODE/PMAM4Solver.class.st | 2 +- src/Math-ODE/PMBDF2Solver.class.st | 2 +- src/Math-ODE/PMBDF3Solver.class.st | 2 +- src/Math-ODE/PMBDF4Solver.class.st | 2 +- src/Math-ODE/PMButcherTableauStepper.class.st | 9 +- src/Math-ODE/PMStepper.class.st | 2 +- src/Math-Permutation/PMPermutation.class.st | 6 +- .../SortedCollection.extension.st | 16 +- src/Math-TSNE/PMTSNE.class.st | 19 +- .../PMAccuracyFindKeyTest.class.st | 47 +++++ .../PMAccuracyTest.class.st | 98 +++-------- .../PMAccuracyTestExample.class.st | 120 ++++++++----- .../PMDataTreeTest.class.st | 116 +++++++++++++ .../PMArbitraryPrecisionFloatTest.class.st | 6 +- .../PMGradientAndHessianTest.class.st | 8 +- .../PMAnotherChromosomeManagerTest.class.st | 49 ++---- .../PMAnotherGeneticOptimizerTest.class.st | 12 +- .../PMErrorOfParameterFunctionTest.class.st | 16 +- .../PMGeneralFunctionFitTest.class.st | 2 +- src/Math-Tests-KDTree/PMKDTreeTest.class.st | 84 ++++----- src/Math-Tests-KDTree/PMNNStoreTest.class.st | 8 +- src/Math-Tests-Matrix/PMMatrixTest.class.st | 2 +- .../PMSingularValueDecompositionTest.class.st | 47 ++--- .../PMGeneticOptimizerBugsTest.class.st | 2 +- .../PMPermutationTest.class.st | 16 +- .../PMStandardizationScalerTest.class.st | 8 +- .../PMQuantileTest.class.st | 164 +++--------------- src/Math-Tests-TSNE/PMTSNETest.class.st | 7 +- 51 files changed, 495 insertions(+), 510 deletions(-) create mode 100644 FUNDING.yml create mode 100644 src/Math-Tests-Accuracy/PMAccuracyFindKeyTest.class.st create mode 100644 src/Math-Tests-Accuracy/PMDataTreeTest.class.st diff --git a/.travis.yml b/.travis.yml index 896d023f5..919b37d1d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,9 +6,10 @@ os: - osx smalltalk: - - Pharo-6.1 - Pharo32-7.0 - Pharo64-7.0 + - Pharo32-8.0 + - Pharo64-8.0 matrix: fast_finish: true diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 258ee2814..1a94311dc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,7 +3,7 @@ This file is currently not complete but will be improve step by step. # Contributing code -Use last version of Pharo 7.0 in order to use Iceberg. +Use last version of Pharo 8.0 in order to use Iceberg. ## Fork the Pharo repository All changes you'll do will be versionned in your own fork of the [PolyMath repository](https://github.com/PolyMathOrg/PolyMath). Then, from your fork you'll be able to issue pull requests to PolyMath, where they will be reviewed, and luckily, integrated. @@ -11,7 +11,7 @@ All changes you'll do will be versionned in your own fork of the [PolyMath repos Go to PolyMath github's repository and click on the fork button on the top right. Yes, this means that you'll need a github account to contribute to PolyMath, yes. ## Load last dev version of PolyMath -In a fresh Pharo 7.0 image, load last development version of Polymath : +In a fresh Pharo 8.0 image, load last development version of Polymath : ```Smalltalk Metacello new diff --git a/FUNDING.yml b/FUNDING.yml new file mode 100644 index 000000000..15ba50249 --- /dev/null +++ b/FUNDING.yml @@ -0,0 +1 @@ +github: SergeStinckwich diff --git a/README.md b/README.md index c35651379..5570dcfe6 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@

Scientific Computing with Pharo
- Explore the docs » + Explore the docs »

Report a defect @@ -19,11 +19,12 @@ Screenshot 2019-04-24 at 11 12 57 -You can load PolyMath 1.0 into a fresh Pharo 7.0 image with: + +You can load PolyMath 1.0.1 into a fresh Pharo 7.0 image with: ```Smalltalk Metacello new - repository: 'github://PolyMathOrg/PolyMath:v1.0/src'; + repository: 'github://PolyMathOrg/PolyMath:v1.0.1/src'; baseline: 'PolyMath'; load ``` @@ -37,7 +38,8 @@ Metacello new load ``` -We have **806** green tests ! At the moment, all the development happens in the master branch (we are using trunk-based development). + +We have **815** green tests ! At the moment, all the development happens in the master branch (we are using trunk-based development). PolyMath is a Pharo project, similar to existing scientific libraries like NumPy, SciPy for Python or SciRuby for Ruby. PolyMath already provides the following basic functionalities: - complex and quaternions extensions, diff --git a/appveyor.yml b/appveyor.yml index bce180177..e12b117eb 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -6,7 +6,7 @@ environment: CYG_MIRROR: http://cygwin.mirror.constant.com SCI_RUN: /cygdrive/c/smalltalkCI-master/run.sh matrix: - - SMALLTALK: Pharo-7.0 + - SMALLTALK: Pharo-8.0 platform: - x86 diff --git a/src/BaselineOfPolyMath/BaselineOfPolyMath.class.st b/src/BaselineOfPolyMath/BaselineOfPolyMath.class.st index 57a688763..979eed4b8 100644 --- a/src/BaselineOfPolyMath/BaselineOfPolyMath.class.st +++ b/src/BaselineOfPolyMath/BaselineOfPolyMath.class.st @@ -177,19 +177,13 @@ BaselineOfPolyMath >> projectClass [ { #category : #dependencies } BaselineOfPolyMath >> sMark: spec [ spec - project: 'SMark' - with: [ spec - className: #ConfigurationOfSMark; - versionString: '1.0.3'; - repository: 'http://smalltalkhub.com/mc/StefanMarr/SMark/main' ] + baseline: 'SMark' + with: [ spec repository: 'github://smarr/SMark:v1.0.4/repository' ] ] { #category : #dependencies } BaselineOfPolyMath >> xmlWriter: spec [ spec - project: 'XMLWriter' - with: [ spec - className: #ConfigurationOfXMLWriter; - versionString: '2.3.10'; - repository: 'http://smalltalkhub.com/mc/PharoExtras/XMLWriter/main' ] + baseline: 'XMLWriter' + with: [ spec repository: 'github://pharo-contributions/XML-XMLWriter:2.9.0/src' ] ] diff --git a/src/ExtendedNumberParser/ExtendedNumberParser.class.st b/src/ExtendedNumberParser/ExtendedNumberParser.class.st index a025e00ea..2bc68c444 100644 --- a/src/ExtendedNumberParser/ExtendedNumberParser.class.st +++ b/src/ExtendedNumberParser/ExtendedNumberParser.class.st @@ -166,7 +166,7 @@ ExtendedNumberParser >> readNumberWithFractionPartNumberOfTrailingZeroInIntegerP fractionPart := 0. numberOfNonZeroFractionDigits := 0. numberOfTrailingZeroInFractionPart := 0] - ifNotNil: [. + ifNotNil: [ numberOfNonZeroFractionDigits := lastNonZero. numberOfTrailingZeroInFractionPart := nDigits - lastNonZero]. self readExponent diff --git a/src/Math-Accuracy-Core/PMAccuracy.class.st b/src/Math-Accuracy-Core/PMAccuracy.class.st index 1e74de0a5..e8fdff98f 100644 --- a/src/Math-Accuracy-Core/PMAccuracy.class.st +++ b/src/Math-Accuracy-Core/PMAccuracy.class.st @@ -19,7 +19,7 @@ Class { #classVars : [ 'DecimalPlaces' ], - #category : 'Math-Accuracy-Core' + #category : #'Math-Accuracy-Core' } { #category : #accessing } @@ -134,7 +134,7 @@ PMAccuracy >> argumentAt: aName [ PMAccuracy >> asArray: aCol [ ^(aCol isCollection and: [ aCol isSequenceable and: [aCol isString not] ]) ifTrue: [ aCol asArray ] - ifFalse: [ {aCol} ] + ifFalse: [ Array with: aCol ] ] { #category : #private } @@ -302,7 +302,7 @@ no isCollection ifFalse: [^1]. PMAccuracy >> numberOfDifferentResultsAt: aname [ |no| no := self resultsAt: aname. - no isCollection ifFalse:[no:={no}]. + no isCollection ifFalse:[no:= Array with: no]. ^ no first isCollection ifTrue: [ no size ] ifFalse: [ 1 ] ] @@ -426,7 +426,7 @@ PMAccuracy >> run: anArrayOfNames [ << 'Report for: '; << self class name; cr. - self ifSeveralterations: [ aStream << 'iterations: ' << iterations; cr ]. + self ifSeveralterations: [ aStream << 'iterations: ' << iterations asString; cr ]. (self tree: dataTree removeAll type: self class name data: 'names') at: 'iterations' put: iterations; at: 'names' put: (self tree: KeyedTree new type: 'names' data: a). diff --git a/src/Math-Benchmarks-ODE/PMODEBenchmark.class.st b/src/Math-Benchmarks-ODE/PMODEBenchmark.class.st index 031e63aca..79c3b7445 100644 --- a/src/Math-Benchmarks-ODE/PMODEBenchmark.class.st +++ b/src/Math-Benchmarks-ODE/PMODEBenchmark.class.st @@ -38,7 +38,7 @@ PMODEBenchmark class >> runAllToXML: numOfIterations [ xml. writer tag: 'smark' with: [ (self runAll: numOfIterations) do: [ :runner | - writer tag: 'suite' attributes: { #name -> runner suite class name asString } asDictionary with: [ + writer tag: 'suite' attributes: (Dictionary with: #name -> runner suite class name asString) with: [ runner results keysAndValuesDo: [ :key :value | writer tag: key with: ((value inject: 0 into: [ :subTotal :result | subTotal + result total ]) / value size) asFloat asString] ] ] ]. diff --git a/src/Math-Core-Process/PMFixpoint.class.st b/src/Math-Core-Process/PMFixpoint.class.st index 52f6d3bd1..60a10baeb 100644 --- a/src/Math-Core-Process/PMFixpoint.class.st +++ b/src/Math-Core-Process/PMFixpoint.class.st @@ -64,7 +64,7 @@ verbose ifFalse: [ ^self ]. GrowlMorph openWithLabel: 'Info' contents: ('{1} iterations used. -warning: {2}-cycle detected' format: {iterations. cycleLength}) +warning: {2}-cycle detected' format: (Array with: iterations with: cycleLength)) color: Color gray muchDarker ] @@ -151,7 +151,7 @@ PMFixpoint >> simpleInfo [ verbose ifFalse: [ ^self ]. GrowlMorph openWithLabel: 'Info' - contents: ('{1} iterations needed.' format: {iterations}) + contents: ('{1} iterations needed.' format: (Array with: iterations)) color: Color green muchDarker ] @@ -161,7 +161,7 @@ verbose ifFalse: [ ^self ]. GrowlMorph openWithLabel: 'Warning' contents: ('maximumIterations ({1}) reached. -you can run evaluate a second time' format: {maximumIterations}) +you can run evaluate a second time' format: (Array with: maximumIterations)) color: Color orange darker ] diff --git a/src/Math-Core/PMVector.class.st b/src/Math-Core/PMVector.class.st index 4820c79d1..7a558556e 100644 --- a/src/Math-Core/PMVector.class.st +++ b/src/Math-Core/PMVector.class.st @@ -203,7 +203,7 @@ PMVector >> householder [ put: ((x <=0) ifTrue: [x -u] ifFalse: [0 - s / (x + u)]). b :=(v at: 1) squared * 2 / (s + (v at: 1) squared). v := v / (v at: 1) ]. - ^{b. v} + ^Array with: b with: v ] { #category : #operation } diff --git a/src/Math-FastFourierTransform/PMFastFourierTransform.class.st b/src/Math-FastFourierTransform/PMFastFourierTransform.class.st index 4b80b99ca..d1c6d2f69 100644 --- a/src/Math-FastFourierTransform/PMFastFourierTransform.class.st +++ b/src/Math-FastFourierTransform/PMFastFourierTransform.class.st @@ -78,9 +78,7 @@ PMFastFourierTransform >> initPermTable [ r := (i - 1 bitReverse: nu) + 1. r > i ifTrue: [ permTable - add: - {i. - r} ] ] + add: (Array with: i with: r) ] ] ] { #category : #initializing } diff --git a/src/Math-FunctionFit/PMAnotherGeneticOptimizer.class.st b/src/Math-FunctionFit/PMAnotherGeneticOptimizer.class.st index 400d645c6..fefe31be6 100644 --- a/src/Math-FunctionFit/PMAnotherGeneticOptimizer.class.st +++ b/src/Math-FunctionFit/PMAnotherGeneticOptimizer.class.st @@ -205,10 +205,10 @@ PMAnotherGeneticOptimizer >> printOn: aStream [ { #category : #operation } PMAnotherGeneticOptimizer >> processRandomParents: aNumberArray [ "puts the better chromosome at the first place (is eg necessary for lineCrossOver:and:)" - |pos1 pos2 c| - pos1:=self randomIndex: aNumberArray. - pos2:=self randomIndex: aNumberArray. - pos1>pos2 ifTrue:[c:=pos1.pos1:=pos2. pos2:=c]. + | pos1 pos2 c | + pos1 := self randomIndex: aNumberArray. + pos2 := self randomIndex: aNumberArray. + pos1 > pos2 ifTrue: [c := pos1. pos1 := pos2. pos2 := c]. chromosomeManager process: ( bestPoints at: pos1) position and: ( bestPoints at: pos2) position. ] @@ -219,7 +219,7 @@ PMAnotherGeneticOptimizer >> rangeScale [ | size best| size:=bestPoints size -1. best := 0.0 . -^(size to:1 by:( -1))collect: [:i|best:=2*i/(size*(size+1))+best]. +^(size to: 1 by: (-1)) collect: [:i | best := 2 * i / (size * (size + 1)) + best]. ] diff --git a/src/Math-FunctionFit/PMGeneralFunctionFit.class.st b/src/Math-FunctionFit/PMGeneralFunctionFit.class.st index 1f2513218..811ed5f74 100644 --- a/src/Math-FunctionFit/PMGeneralFunctionFit.class.st +++ b/src/Math-FunctionFit/PMGeneralFunctionFit.class.st @@ -132,8 +132,10 @@ n:=0. [ self quartile: max. self evaluate. errorCol:= self errorCollection sort. - d2:=(errorFunction parameterSize to: (errorCol size -4) ) collect: [:i| {i+2. - (2*(errorCol at: i)) - (errorCol at: i+1) - (2*(errorCol at: i+2))- (errorCol at: i+3)+(2*(errorCol at: i+4))} ]. + d2:=(errorFunction parameterSize to: (errorCol size -4) ) collect: [:i| + Array + with: (i+2) + with: ((2*(errorCol at: i)) - (errorCol at: i+1) - (2*(errorCol at: i+2))- (errorCol at: i+3)+(2*(errorCol at: i+4))) ]. [max :=#(5 0). d2 do: [:d|((d at: 2) >= (max at:2)) ifTrue: [max :=d]]. (max first = (d2 last first))ifTrue: [ @@ -296,7 +298,7 @@ PMGeneralFunctionFit >> truncateData [ |ec ei | dataTruncated ifTrue: [^Error signal:'data is already truncated']. ec:=self errorCollection . -ei:=(ec withIndexCollect: [:e :i|{e.i}]). +ei:=(ec withIndexCollect: [:e :i| Array with: e with: i]). ei:=(ei sort:[:a :b|a first> withAll: aCollectionOfCollections [ "make a KDTree from a SequenceableCollection of SequenceableCollections ,which is an ordered Collection of points in a n-dimensional space. the nearest neighbour search then returns the indices of the neighbours" -|c| -c :=aCollectionOfCollections withIndexCollect: [:v :i| {i.v.}] . -^super withAll: c. +^super withAll: (aCollectionOfCollections withIndexCollect: [:v :i| Array with: i with: v ]). ] { #category : #private } PMIndexedKDTree >> add: aDistance to: aNNStore [ -aNNStore add: {aDistance . {index . value}} . +aNNStore add: (Array with: aDistance with: (Array with: index with: value)) . ] { #category : #private } @@ -36,7 +34,7 @@ PMIndexedKDTree >> nnSearch: aSequenceableCollection i: anInt [ |n| n :=PMNNStore new: anInt . self nnSearch: aSequenceableCollection asFloatArray near: n . -^anInt =1 ifTrue: [n data first first ] ifFalse: [n completeData collect: [:i | {(i at:2)first . i first}] ] +^anInt =1 ifTrue: [n data first first ] ifFalse: [n completeData collect: [:i | Array with: (i at:2) first with: i first] ] ] { #category : #private } diff --git a/src/Math-KDTree/PMKDTree.class.st b/src/Math-KDTree/PMKDTree.class.st index 37223d1c7..9005745a9 100644 --- a/src/Math-KDTree/PMKDTree.class.st +++ b/src/Math-KDTree/PMKDTree.class.st @@ -24,7 +24,7 @@ aCollectionOfCollections first ifEmpty: [self error: 'KDTree withAll: error' ]. { #category : #private } PMKDTree >> add: aDistance to: aNNStore [ -aNNStore add: {aDistance . value} . +aNNStore add: (Array with: aDistance with: value) . ] { #category : #initialize } diff --git a/src/Math-KDTree/PMNNStore.class.st b/src/Math-KDTree/PMNNStore.class.st index b086ef631..76fdcd77e 100644 --- a/src/Math-KDTree/PMNNStore.class.st +++ b/src/Math-KDTree/PMNNStore.class.st @@ -16,7 +16,7 @@ Class { { #category : #'instance creation' } PMNNStore class >> new: anInt [ -^((super new: anInt) atAllPut: {Float infinity. nil} )initialize +^((super new: anInt) atAllPut: (Array with: Float infinity with: nil))initialize ] { #category : #'instance creation' } @@ -30,7 +30,7 @@ PMNNStore class >> newFrom: aCollectionWithSortingIndex [ PMNNStore class >> withAll: aCollection [ "this is the peferable form of instance creation for subclasses since freeIndex is correctly initialized this way. then 'sortFor:' must be overwritten and called at least once (!); an example is StupidNN. the other possibility is to use 'new:' and to fill NNStore subclass with 'add:' . the advantage is, that NNStore has not to be filled completely this way and the sorting logic can be applied outside of the subclass without sortFor: (see also comment on add:). you cant enter the sorting index with the method withAll: . if you want to do that, use 'newFrom:' instead" -^(super withAll: (aCollection collect: [:coll| {nil. coll}]))lastUsedIndex: aCollection size +^(super withAll: (aCollection collect: [:coll| Array with: nil with: coll]))lastUsedIndex: aCollection size ] { #category : #comparing } diff --git a/src/Math-KolmogorovSmirnov/PMKolmogorovSmirnov2Sample.class.st b/src/Math-KolmogorovSmirnov/PMKolmogorovSmirnov2Sample.class.st index 0791765c8..ab0422b18 100644 --- a/src/Math-KolmogorovSmirnov/PMKolmogorovSmirnov2Sample.class.st +++ b/src/Math-KolmogorovSmirnov/PMKolmogorovSmirnov2Sample.class.st @@ -63,17 +63,11 @@ PMKolmogorovSmirnov2Sample >> initCachedUCalculation [ cij := self cFrom: i and: j. i * j = 0 ifTrue: [ cij ] - ifFalse: [ cij - * - ((uCalcBlock - value: - {i. - (j - 1)}) - + - (uCalcBlock - value: - {(i - 1). - j})) ] ] memoized + ifFalse: [ cij * ( + (uCalcBlock value: (Array with: i with: j - 1)) + + + (uCalcBlock value: (Array with: i - 1 with: j)) + ) ] ] memoized ] { #category : #initialization } @@ -123,7 +117,7 @@ PMKolmogorovSmirnov2Sample >> ksStatistic [ { #category : #private } PMKolmogorovSmirnov2Sample >> makeCDFOf: aCollection intoFirst: aBoolean [ "if aCollection consists of numbers, -it returns a sorted array of (number->{cdf.aBoolean})" +it returns a sorted array of (number-> (Array with: cdf with: aBoolean))" | cd s result | cd := 0. @@ -131,10 +125,7 @@ it returns a sorted array of (number->{cdf.aBoolean})" result := aCollection asBag sortedElements do: [ :a | cd := a value / s + cd. - a - value: - {cd. - aBoolean} ]. + a value: (Array with: cd with: aBoolean) ]. ^ aBoolean ifTrue: [ data := result ] ifFalse: [ compareWith := result ] @@ -154,10 +145,8 @@ Kim, P. J. & Jennrich, R. I. in 'Selected Tables in Mathematical Statistics Volume I' (1973)." ksStatistic ifNil: [ self ksStatistic ]. - ^ (uCalcBlock - value: - {smallSize. - bigSize}) / (smallSize + bigSize take: smallSize) + ^ (uCalcBlock value: (Array with: smallSize with: bigSize)) + / (smallSize + bigSize take: smallSize) ] { #category : #printing } diff --git a/src/Math-Matrix/PMMatrix.class.st b/src/Math-Matrix/PMMatrix.class.st index c4042dd64..7e93d3fe2 100644 --- a/src/Math-Matrix/PMMatrix.class.st +++ b/src/Math-Matrix/PMMatrix.class.st @@ -670,7 +670,7 @@ PMMatrix >> qrFactorization [ i>0 ifTrue: [ r :=PMMatrix rows: (r rows copyFrom: 1 to: colSize). i := q numberOfColumns - i. q := PMMatrix rows: ( q rows collect: [:row| row copyFrom: 1 to: i]) ]. - ^{q. r} + ^Array with: q with: r ] { #category : #'as yet unclassified' } @@ -729,9 +729,7 @@ PMMatrix >> qrFactorizationWithPivoting [ i := q numberOfColumns - i. pivot := pivot copyFrom: 1 to: i. q := PMMatrix rows: (q rows collect: [ :row | row copyFrom: 1 to: i ]) ]. - ^ {q. - r. - pivot} + ^ Array with: q with: r with: pivot ] { #category : #'as yet unclassified' } diff --git a/src/Math-ODE/PMAB2Solver.class.st b/src/Math-ODE/PMAB2Solver.class.st index c946be1ba..b58b048cf 100644 --- a/src/Math-ODE/PMAB2Solver.class.st +++ b/src/Math-ODE/PMAB2Solver.class.st @@ -64,7 +64,7 @@ PMAB2Solver >> mainStepsPrevState: prevState startTime: initialTime endTime: end self announceState: state time: time + self dt. lastTime := time + self dt]. - ^ {previousState . state} + ^ Array with: previousState with: state ] { #category : #'as yet unclassified' } diff --git a/src/Math-ODE/PMAB3Solver.class.st b/src/Math-ODE/PMAB3Solver.class.st index 3539105ba..f0a3580b8 100644 --- a/src/Math-ODE/PMAB3Solver.class.st +++ b/src/Math-ODE/PMAB3Solver.class.st @@ -56,7 +56,7 @@ PMAB3Solver >> mainStepsPrevState: prevState prevPrevState: prevPrevState startT self announceState: state time: time + self dt. lastTime := time + (3*self dt)]. - ^ { previousPrevState. previousState} + ^ Array with: previousPrevState with: previousState ] diff --git a/src/Math-ODE/PMAB4Solver.class.st b/src/Math-ODE/PMAB4Solver.class.st index 70f008831..1b9779408 100644 --- a/src/Math-ODE/PMAB4Solver.class.st +++ b/src/Math-ODE/PMAB4Solver.class.st @@ -63,7 +63,7 @@ PMAB4Solver >> mainStepsPrevState: prevState prevPrevState: prevPrevState initSt self announceState: state time: time + self dt. lastTime := time + (4*self dt)]. - ^ { initialState. previousPrevState. previousState} + ^ Array with: initialState with: previousPrevState with: previousState ] { #category : #'as yet unclassified' } diff --git a/src/Math-ODE/PMAM3Solver.class.st b/src/Math-ODE/PMAM3Solver.class.st index 23a0d9811..8c8e04fdb 100644 --- a/src/Math-ODE/PMAM3Solver.class.st +++ b/src/Math-ODE/PMAM3Solver.class.st @@ -64,7 +64,7 @@ PMAM3Solver >> mainStepsPrevState: prevState startTime: initialTime endTime: end self announceState: state time: time + self dt. lastTime := time + self dt]. - ^ {previousState . state} + ^ Array with: previousState with: state ] { #category : #'as yet unclassified' } diff --git a/src/Math-ODE/PMAM4Solver.class.st b/src/Math-ODE/PMAM4Solver.class.st index 4763c3ccd..a403f8ff3 100644 --- a/src/Math-ODE/PMAM4Solver.class.st +++ b/src/Math-ODE/PMAM4Solver.class.st @@ -55,7 +55,7 @@ PMAM4Solver >> mainStepsPrevState: prevState prevPrevState: prevPrevState startT "announce step results" self announceState: state time: time + self dt. lastTime := time + self dt]. - ^ { previousPrevState. previousState } + ^ Array with: previousPrevState with: previousState ] { #category : #'as yet unclassified' } diff --git a/src/Math-ODE/PMBDF2Solver.class.st b/src/Math-ODE/PMBDF2Solver.class.st index 2860a0f71..109a59f4a 100644 --- a/src/Math-ODE/PMBDF2Solver.class.st +++ b/src/Math-ODE/PMBDF2Solver.class.st @@ -65,7 +65,7 @@ PMBDF2Solver >> mainStepsPrevState: prevState startTime: initialTime endTime: en self announceState: state time: time + self dt. lastTime := time + self dt]. - ^ {previousState . state} + ^ Array with: previousState with: state ] { #category : #'as yet unclassified' } diff --git a/src/Math-ODE/PMBDF3Solver.class.st b/src/Math-ODE/PMBDF3Solver.class.st index 20ce58478..b6972b9d5 100644 --- a/src/Math-ODE/PMBDF3Solver.class.st +++ b/src/Math-ODE/PMBDF3Solver.class.st @@ -54,7 +54,7 @@ PMBDF3Solver >> mainStepsPrevState: prevState prevPrevState: prevPrevState start "announce step results" self announceState: state time: time + self dt. lastTime := time + self dt]. - ^ { previousPrevState. previousState } + ^ Array with: previousPrevState with: previousState ] { #category : #'as yet unclassified' } diff --git a/src/Math-ODE/PMBDF4Solver.class.st b/src/Math-ODE/PMBDF4Solver.class.st index 737103eee..e267884bb 100644 --- a/src/Math-ODE/PMBDF4Solver.class.st +++ b/src/Math-ODE/PMBDF4Solver.class.st @@ -62,7 +62,7 @@ PMBDF4Solver >> mainStepsPrevState: prevState prevPrevState: prevPrevState initS self announceState: state time: time + self dt. lastTime := time + self dt]. - ^ { initialState. previousPrevState. previousState} + ^ Array with: initialState with: previousPrevState with: previousState ] { #category : #'as yet unclassified' } diff --git a/src/Math-ODE/PMButcherTableauStepper.class.st b/src/Math-ODE/PMButcherTableauStepper.class.st index d8ce5f0d9..fbc3986a4 100644 --- a/src/Math-ODE/PMButcherTableauStepper.class.st +++ b/src/Math-ODE/PMButcherTableauStepper.class.st @@ -58,9 +58,10 @@ PMButcherTableauStepper class >> stageWeights: anArray stageCoefficients: aMatri ] { #category : #stepping } -PMButcherTableauStepper >> doStep: aStateTime stepSize: dt [ +PMButcherTableauStepper >> doStep: aStateTime stepSize: stepSize [ "not complete" - | stages stageCount stateDifference| + | stages stageCount stateDifference | + dt := stepSize. "???" self isInitialized. stageCount := stageIncrements size. stages := Array new: stageCount. @@ -80,8 +81,8 @@ PMButcherTableauStepper >> doStep: aStateTime stepSize: dt [ ] { #category : #stepping } -PMButcherTableauStepper >> doStep: aState time: aTime stepSize: dt [ - ^ self doStep: (PMStateTime state: aState time: aTime) stepSize: dt. +PMButcherTableauStepper >> doStep: aState time: aTime stepSize: stepSize [ + ^ self doStep: (PMStateTime state: aState time: aTime) stepSize: stepSize. ] { #category : #assertion } diff --git a/src/Math-ODE/PMStepper.class.st b/src/Math-ODE/PMStepper.class.st index 658af2ca0..ec26bd0da 100644 --- a/src/Math-ODE/PMStepper.class.st +++ b/src/Math-ODE/PMStepper.class.st @@ -32,7 +32,7 @@ PMStepper class >> order [ ] { #category : #stepping } -PMStepper >> doStep: aState time: t stepSize: dt [ +PMStepper >> doStep: aState time: t stepSize: stepSize [ "This method should take one step from inState at time t of size dt, then answer it" self subclassResponsibility ] diff --git a/src/Math-Permutation/PMPermutation.class.st b/src/Math-Permutation/PMPermutation.class.st index f9cc7c69e..57c1e3510 100644 --- a/src/Math-Permutation/PMPermutation.class.st +++ b/src/Math-Permutation/PMPermutation.class.st @@ -128,9 +128,9 @@ block:=[:nandk||n k| (n=k and:[n isZero]) ifTrue:[1] ifFalse:[ (n * k) isZero - ifTrue:[0] - ifFalse:[ (block value:{n-1.k-1})+((n-1)*(block value:{n-1.k}))]]]memoized . -^block value:{anInteger . anotherInteger } + ifTrue:[0] + ifFalse:[ (block value: (Array with: n-1 with: k-1))+((n-1)*(block value:(Array with: n-1 with: k)))]]]memoized . +^block value: (Array with: anInteger with: anotherInteger) ] { #category : #converting } diff --git a/src/Math-Quantile/SortedCollection.extension.st b/src/Math-Quantile/SortedCollection.extension.st index 032eed099..186a58771 100644 --- a/src/Math-Quantile/SortedCollection.extension.st +++ b/src/Math-Quantile/SortedCollection.extension.st @@ -2,12 +2,12 @@ Extension { #name : #SortedCollection } { #category : #'*Math-Quantile' } SortedCollection >> california [ - ^ {0 . 0 . 0 . 1} + ^ Array with: 0 with: 0 with: 0 with: 1 ] { #category : #'*Math-Quantile' } SortedCollection >> closestObservation [ - ^ {1/2 . 0 . 0 . 0} + ^ Array with: 1/2 with: 0 with: 0 with: 0 ] { #category : #'*Math-Quantile' } @@ -26,7 +26,7 @@ SortedCollection class >> example2 [ { #category : #'*Math-Quantile' } SortedCollection >> hydrologist [ - ^ {1/2 . 0 . 0 . 1} + ^ Array with: 1/2 with: 0 with: 0 with: 1 ] { #category : #'*Math-Quantile' } @@ -38,22 +38,22 @@ SortedCollection >> interQuartileRange [ { #category : #'*Math-Quantile' } SortedCollection >> inverseCDF [ - ^ {0 . 0 . 1 . 0} + ^ Array with: 0 with: 0 with: 1 with: 0 ] { #category : #'*Math-Quantile' } SortedCollection >> medianBased [ - ^ {1/3 . 1/3 . 0 . 1} + ^ Array with: 1/3 with: 1/3 with: 0 with: 1 ] { #category : #'*Math-Quantile' } SortedCollection >> modeBased [ - ^ {1 . -1 . 0 . 1} + ^ Array with: 1 with: -1 with: 0 with: 1 ] { #category : #'*Math-Quantile' } SortedCollection >> normalDistribution [ - ^ {3/8 . 1/4 . 0 . 1} + ^ Array with: 3/8 with: 1/4 with: 0 with: 1 ] { #category : #'*Math-Quantile' } @@ -95,5 +95,5 @@ SortedCollection >> quantile: aProbability withProbs: anArray [ { #category : #'*Math-Quantile' } SortedCollection >> weibull [ - ^ {0 . 1 . 0 . 1} + ^ Array with: 0 with: 1 with: 0 with: 1 ] diff --git a/src/Math-TSNE/PMTSNE.class.st b/src/Math-TSNE/PMTSNE.class.st index ddeaaea0c..eed330426 100644 --- a/src/Math-TSNE/PMTSNE.class.st +++ b/src/Math-TSNE/PMTSNE.class.st @@ -80,8 +80,8 @@ PMTSNE class >> exampleGridWithVizualization [ "We assign a color to the elements" rec := Rectangle encompassing: (tsne y rows collect: [:row | row first @ row second ]). - xscale := TSScale linear domain: { rec origin x. rec corner x }. - yscale := TSScale linear domain: { rec origin y. rec corner y }. + xscale := TSScale linear domain: (Array with rec origin x with: rec corner x). + yscale := TSScale linear domain: (Array with rec origin y with: rec corner y). s := RSShapeBuilder circle size: 5; color: [:vec | Color @@ -153,7 +153,7 @@ PMTSNE class >> gridDataGeneratorOf: size [ | array i | array := Array new: size*size. i := 1. - 1 to: size do: [ :x | 1 to: size do: [ :y | array at: i put: {x. y.}. + 1 to: size do: [ :x | 1 to: size do: [ :y | array at: i put: (Array with: x with: y). i:=i+1] ]. ^ PMMatrix rows: array ] @@ -213,7 +213,7 @@ PMTSNE >> computeGradient [ PMTSNE >> computeLowDimensionalAffinities [ "Computes affinity of the reduced dimension/output" - | num sumNum q | + | num sumNum | num := self computeLowDimensionalStudentT. sumNum := num sum sum max: (Float epsilon). q := num collect: [:element | @@ -239,7 +239,7 @@ PMTSNE >> computeLowDimensionalStudentT [ { #category : #accessing } PMTSNE >> computePValues [ "Computes joint probablity matrix P" - | p sumP | + | sumP | p := self computePairwiseAffinities. p := p + p transpose. sumP := p sum sum. @@ -257,7 +257,7 @@ PMTSNE >> computePairwiseAffinities [ binary search. The precision is selected based on input perplexity. " - | p d beta logU n betaMin betaMax distanceVector pVector entropy tries entropyDiff | + | d beta logU n betaMin betaMax distanceVector pVector entropy tries entropyDiff | n := x numberOfRows. d := self computePairwiseDistances. p := PMMatrix zerosRows: n cols: n. @@ -272,7 +272,7 @@ PMTSNE >> computePairwiseAffinities [ 1 to: n do: [ :i | "Job progress gets updated every 10 rows" (i % 10 = 0) ifTrue: [ - job title: ('' join: {'Step 2/3: Computing joint probablity for point '. i asString. ' of '. n asString}). + job title: ('Step 2/3: Computing joint probablity for point {1} of {2}' format: (Array with: i with: n)). job progress: (i/n). ]. @@ -653,8 +653,9 @@ PMTSNE >> updateProgressWithError [ ] ]. error := error sum sum ]. - job title: ('' join: - {'Step 3/3: Performing gradient descent '. iterations. '/'. maxIter. ' error = '. error} + job title: ( + 'Step 3/3: Performing gradient descent {1}/{2} error = {3}' + format: (Array with: iterations with: maxIter with: error) ). job progress: iterations / maxIter. ] diff --git a/src/Math-Tests-Accuracy/PMAccuracyFindKeyTest.class.st b/src/Math-Tests-Accuracy/PMAccuracyFindKeyTest.class.st new file mode 100644 index 000000000..a94b0e144 --- /dev/null +++ b/src/Math-Tests-Accuracy/PMAccuracyFindKeyTest.class.st @@ -0,0 +1,47 @@ +" +This test case exercises the findKey: message with some regression tests. +" +Class { + #name : #PMAccuracyFindKeyTest, + #superclass : #TestCase, + #instVars : [ + 'accuracy' + ], + #category : #'Math-Tests-Accuracy' +} + +{ #category : #tests } +PMAccuracyFindKeyTest >> assertKeyFor: selector equals: expected [ + self assert: (accuracy findKey: selector) equals: expected +] + +{ #category : #running } +PMAccuracyFindKeyTest >> setUp [ + super setUp. + accuracy := PMAccuracyTestExample new. + +] + +{ #category : #tests } +PMAccuracyFindKeyTest >> testFindKeyReturnsAllTheRestStringWhenSelectorCorrespondsToNonExistentProperty [ + | selector | + selector := 'NonExistent'. + + self assertKeyFor: selector equals: 'AllTheRest' +] + +{ #category : #tests } +PMAccuracyFindKeyTest >> testFindKeyReturnsAllTheRestStringWhenSelectorIsInitialize [ + | selector | + selector := 'initialize'. + + self assertKeyFor: selector equals: 'AllTheRest' +] + +{ #category : #tests } +PMAccuracyFindKeyTest >> testFindKeyReturnsPropertyWhenSelectorIsSuffixOfInitializePropertyMessage [ + | selector | + selector := 'Aaa'. + + self assertKeyFor: selector equals: 'Aaa' +] diff --git a/src/Math-Tests-Accuracy/PMAccuracyTest.class.st b/src/Math-Tests-Accuracy/PMAccuracyTest.class.st index cb68ab31c..929834561 100644 --- a/src/Math-Tests-Accuracy/PMAccuracyTest.class.st +++ b/src/Math-Tests-Accuracy/PMAccuracyTest.class.st @@ -19,15 +19,16 @@ PMAccuracyTest >> initialize [ ] { #category : #running } -PMAccuracyTest >> setUp [ +PMAccuracyTest >> setUp [ + super setUp. a := PMAccuracyTestExample new. - PMAccuracyTestExample decimalPlaces: 3. + PMAccuracyTestExample decimalPlaces: 3 ] { #category : #running } -PMAccuracyTest >> tearDown [ +PMAccuracyTest >> tearDown [ PMAccuracyTestExample decimalPlaces: dp. - + super tearDown. ] { #category : #tests } @@ -51,21 +52,13 @@ PMAccuracyTest >> testAsArray [ PMAccuracyTest >> testCalcDeviationsInMax [ | r c | c := #(#(1 2 3) #(2 3 6)). - r := {(3 / 2). - (9 / 4). - 4}. + r := Array with: (3 / 2) with: (9 / 4) with: 4. self assert: (a calcDeviations: r in: c max: false) - equals: - {(-100 / 3) asFloat. - (-100 / 9) asFloat. - -25}. + equals: (Array with: (-100 / 3) asFloat with: (-100 / 9) asFloat with: -25). self assert: (a calcDeviations: r in: c max: true) - equals: - {(100 / 3) asFloat. - (100 / 3) asFloat. - 50} + equals: (Array with: (100 / 3) asFloat with: (100 / 3) asFloat with: 50) ] { #category : #tests } @@ -82,44 +75,6 @@ PMAccuracyTest >> testCalcErrorOfRealResult [ equals: Float infinity negated ] -{ #category : #tests } -PMAccuracyTest >> testDataTree [ - | s | - a run. - self assert: (a dataTree atPath: #('iterations')) equals: 1. - self - assert: (a dataTree atPath: #('names' 'data')) - equals: #('Aaa' 'Bbb' 'Ccc' 'Ddd' 'Eee' 'Fff'). - self - assert: (a dataTree atPath: #('names' 'Aaa' #(1 2) #(4 4))) - equals: - (KeyedTree new - at: 'arguments' put: true; - at: 'data' put: #(#(1 1)); - at: 'error' put: #(300.0 300.0); - at: 'expected result' put: #(4 4); - at: 'result' put: #(1 1); - at: 'type' put: 'result'; - yourself). - self - assert: (a dataTree atPath: #('names' 'Aaa' 'data')) - equals: #(#(1 2) #(3 2.8888)). - self - assert: (a dataTree atPath: #('names' 'Bbb' #(3) 'data')) - equals: #(#(2) #(3)). - s := a dataTree atPath: #('names' 'Ccc' #(3)). - self assert: s keys size equals: 5. - s := a dataTree atPath: #('names' 'Fff' 'error'). - self - assert: (s copyFrom: 1 to: 4) - equals: - {0. - Float infinity. - -100.0. - Float infinity negated}. - self assert: (s at: 5) isNaN -] - { #category : #tests } PMAccuracyTest >> testDecimalPlaces [ self assert: a class decimalPlaces equals: 3. @@ -145,16 +100,13 @@ PMAccuracyTest >> testExtremeCollectionmax [ c := #(4 4 2). self assert: (a extremeCollection: c max: true) - equals: {Float infinity negated}. + equals: (Array with: Float infinity negated). self assert: (a extremeCollection: c max: false) - equals: {Float infinity}. + equals: (Array with: Float infinity). self - assert: (a extremeCollection: {c} max: false) - equals: - {Float infinity. - Float infinity. - Float infinity} + assert: (a extremeCollection: (Array with: c) max: false) + equals: (Array with: Float infinity with: Float infinity with: Float infinity) ] { #category : #tests } @@ -298,22 +250,24 @@ PMAccuracyTest >> testResultsKeyForAtPosition [ self assert: (a dataTree - atPath: - {'names'. - 'Ccc'. - #(1). - (a resultsKeyFor: 'Ccc' AtPosition: 1). - 'arguments'}) + atPath: ( + Array + with: 'names' + with: 'Ccc' + with: #(1) + with: (a resultsKeyFor: 'Ccc' AtPosition: 1) + with: 'arguments')) equals: 1. self assert: (a dataTree - atPath: - {'names'. - 'Ccc'. - #(1). - (a resultsKeyFor: 'Ccc' AtPosition: 3). - 'arguments'}) + atPath: ( + Array + with: 'names' + with: 'Ccc' + with: #(1) + with: (a resultsKeyFor: 'Ccc' AtPosition: 3) + with: 'arguments')) equals: 0.9. self assert: (a resultsKeyFor: 'Eee' AtPosition: 2) equals: #(1 3). self diff --git a/src/Math-Tests-Accuracy/PMAccuracyTestExample.class.st b/src/Math-Tests-Accuracy/PMAccuracyTestExample.class.st index 70c90e4a5..59dfb92d1 100644 --- a/src/Math-Tests-Accuracy/PMAccuracyTestExample.class.st +++ b/src/Math-Tests-Accuracy/PMAccuracyTestExample.class.st @@ -15,107 +15,149 @@ Class { { #category : #tests } PMAccuracyTestExample >> checkAaa [ -self argument first ifTrue:[^#(1 1)]. -^{4 +(0.4 * Random new next) . 2} + self argument first + ifTrue: [ ^ #(1 1) ]. + ^ Array with: (4 + (0.4 * Random new next)) with: 2 ] { #category : #tests } PMAccuracyTestExample >> checkBbb [ -^self argument first size +self parameter first + ^ self argument first size + self parameter first ] { #category : #tests } PMAccuracyTestExample >> checkCcc [ -^self argument first +(0.01*self parameter first). + ^ self argument first + (0.01 * self parameter first) ] { #category : #tests } PMAccuracyTestExample >> checkDdd [ -^{2 .3 }asOrderedCollection + ^ OrderedCollection with: 2 with: 3 ] { #category : #tests } PMAccuracyTestExample >> checkEee [ -^{self parameter first .3 } + ^ Array with: self parameter first with: 3 ] { #category : #tests } PMAccuracyTestExample >> checkFff [ -^{0. 0. 1. 0. Float nan} + ^ Array with: 0 with: 0 with: 1 with: 0 with: Float nan ] { #category : #private } PMAccuracyTestExample >> count [ -^count + ^ count +] + +{ #category : #private } +PMAccuracyTestExample >> findKey [ + | s selector | + s := thisContext sender. + selector := s sender method selector. + ^ self findKey: selector +] + +{ #category : #private } +PMAccuracyTestExample >> findKey: selector [ + | matchingMessage | + selector = 'initialize' + ifTrue: [ ^ 'AllTheRest' ]. + matchingMessage := names + detect: [ :name | selector endsWith: name ] + ifNone: [ 'AllTheRest' ]. + ^ matchingMessage ] { #category : #'initialize-release' } -PMAccuracyTestExample >> initialize [ -"this is always necessarily the first thing:" -super initialize . -"this is only for testSetup:" -count:=0. -"now you can set defaults:" -self result: #(#(2)#(3)). -self argument: #(#('a') #('AG')). -self parameter: #(#(1) #(3)) +PMAccuracyTestExample >> initialize [ + "this is always necessarily the first thing:" + super initialize. + "this is only for testSetup:" + count := 0. + "now you can set defaults:" + self result: #(#(2) #(3)). + self argument: #(#('a') #('AG')). + self parameter: #(#(1) #(3)) ] { #category : #'initialize-release' } PMAccuracyTestExample >> initializeAaa [ -"this overrides defaults in #initialize:" -self result: #(#(5 3) #(4 4)). -self argument: #(#(false) #(true)). -self parameter: #(#(1 2) #(3 2.8888)) + "this overrides defaults in #initialize:" + + self result: #(#(5 3) #(4 4)). + self map: 'Aaa' to: #(#(false) #(true)). + self parameter: #(#(1 2) #(3 2.8888)) ] { #category : #'initialize-release' } PMAccuracyTestExample >> initializeCcc [ -"this overrides defaults in initialize" -self result: #((1)(1)(1)). -self argument: #((1)(1.1)(0.9)). + "this overrides defaults in initialize" + + self result: #(#(1) #(1) #(1)). + self map: 'Ccc' to: #(#(1) #(1.1) #(0.9)) ] { #category : #'initialize-release' } PMAccuracyTestExample >> initializeDdd [ -"this overrides defaults in initialize" -self result: #(1.1 2.2). -self argument: #()."necessary since otherwise the default values defined in #initialize would be used" -self parameter: #(). + "this overrides defaults in initialize" + + self result: #(1.1 2.2). + self map: 'Ddd' to: #(). + self parameter: #() ] { #category : #'initialize-release' } PMAccuracyTestExample >> initializeEee [ -"this overrides defaults in initialize" -self result: #(#(1.1 2.2) #(1 3)). + "this overrides defaults in initialize" + self result: #(#(1.1 2.2) #(1 3)) ] { #category : #'initialize-release' } PMAccuracyTestExample >> initializeFff [ -"this overrides defaults in initialize" -self result: #(0 1 0 -2 3). -self argument: nil. -self parameter:nil. + "this overrides defaults in initialize" + + self result: #(0 1 0 -2 3). + self map: 'Fff' to: nil. + self parameter: nil +] + +{ #category : #'initialize-release' } +PMAccuracyTestExample >> map: key to: anArgument [ + arguments + at: key + put: (anArgument ifNotNil: [ :a | self asArray: a ]). + ^ anArgument ] { #category : #running } -PMAccuracyTestExample >> setUp [ -count :=count+1. +PMAccuracyTestExample >> setUp [ + count := count + 1 ] { #category : #running } PMAccuracyTestExample >> tearDown [ -count :=count-(1/5). + count := count - (1 / 5) ] { #category : #private } PMAccuracyTestExample >> testGetterAaa [ -^{ self parameter .self argument.self resultsAt: 'Aaa'.self numberOfDifferentParametersAt: 'Aaa'.self numberOfDifferentResultsAt:'Aaa'} +^Array + with: self parameter + with: self argument + with: (self resultsAt: 'Aaa') + with: (self numberOfDifferentParametersAt: 'Aaa') + with: (self numberOfDifferentResultsAt: 'Aaa') ] { #category : #private } PMAccuracyTestExample >> testGetterBbb [ -^{ self parameter .self argument.self resultsAt: 'Bbb'.self numberOfDifferentParametersAt: 'Bbb'.self numberOfDifferentResultsAt:'Bbb'} +^Array + with: self parameter + with: self argument + with: (self resultsAt: 'Bbb') + with: (self numberOfDifferentParametersAt: 'Bbb') + with: (self numberOfDifferentResultsAt: 'Bbb') ] diff --git a/src/Math-Tests-Accuracy/PMDataTreeTest.class.st b/src/Math-Tests-Accuracy/PMDataTreeTest.class.st new file mode 100644 index 000000000..4de3357a0 --- /dev/null +++ b/src/Math-Tests-Accuracy/PMDataTreeTest.class.st @@ -0,0 +1,116 @@ +" +Class Name: PMDataTreeTest + +Responsibility: exercising the PMAccuracyTestExample's +dataTree message + +Collaborators: PMAccuracyTestExample +" +Class { + #name : #PMDataTreeTest, + #superclass : #TestCase, + #instVars : [ + 'dp', + 'a' + ], + #category : #'Math-Tests-Accuracy' +} + +{ #category : #initialization } +PMDataTreeTest >> initialize [ + super initialize. + dp := PMAccuracyTestExample decimalPlaces +] + +{ #category : #running } +PMDataTreeTest >> setUp [ + super setUp. + a := PMAccuracyTestExample new. + PMAccuracyTestExample decimalPlaces: 3. +] + +{ #category : #running } +PMDataTreeTest >> tearDown [ + PMAccuracyTestExample decimalPlaces: dp. + super tearDown. +] + +{ #category : #tests } +PMDataTreeTest >> testDataTree [ + | keyedTree | + a run. + keyedTree := a dataTree atPath: #('names' 'Ccc' #(3)). + self assert: keyedTree keys size equals: 5. +] + +{ #category : #tests } +PMDataTreeTest >> testThatDataForAaaIsTheCorrespondingParameter [ + | parameterForAaa | + a run. + + parameterForAaa := #(#(1 2) #(3 2.8888)). + self + assert: (a dataTree atPath: #('names' 'Aaa' 'data')) + equals: parameterForAaa. +] + +{ #category : #tests } +PMDataTreeTest >> testThatKeyedTreeContainsArgsDataErrorResultsAndType [ + "SMELL - it's not easy to determine the true purpose of the + test and, perhaps with the exception of the 'expected result', + how input leads to the output. The test also contains many + 'magic' numbers. + " + a run. + self + assert: (a dataTree atPath: #('names' 'Aaa' #(1 2) #(4 4))) + equals: + (KeyedTree new + at: 'arguments' put: true; + at: 'data' put: #(#(1 1)); + at: 'error' put: #(300.0 300.0); + at: 'expected result' put: #(4 4); + at: 'result' put: #(1 1); + at: 'type' put: 'result'; + yourself) +] + +{ #category : #tests } +PMDataTreeTest >> testThatRunIncrementsTheNumberOfIterations [ + "SMELL - we're really testing run, it seems." + a run. + self assert: (a dataTree atPath: #('iterations')) equals: 1. +] + +{ #category : #tests } +PMDataTreeTest >> testThatTheDataForBbbIsTheDefaultResult [ + "SMELL - magic number. This may be coincidental, but the + expected result in this test is that set in + PMAccuracyTestExample's initialize method. + " + | defaultResultAtInitialisation | + a run. + defaultResultAtInitialisation := #(#(2) #(3)). + self + assert: (a dataTree atPath: #('names' 'Bbb' #(3) 'data')) + equals: defaultResultAtInitialisation +] + +{ #category : #tests } +PMDataTreeTest >> testThatTheErrorForFffIsCorrect [ + | error | + a run. + error := a dataTree atPath: #('names' 'Fff' 'error'). + self + assert: (error copyFrom: 1 to: 4) + equals: (Array with: 0 with: Float infinity with: -100.0 with: Float infinity negated). + self assert: (error at: 5) isNaN. +] + +{ #category : #tests } +PMDataTreeTest >> testThatTheNamesAreInitialisationKeys [ + a run. + self + assert: (a dataTree atPath: #('names' 'data')) + equals: #('Aaa' 'Bbb' 'Ccc' 'Ddd' 'Eee' 'Fff') +] diff --git a/src/Math-Tests-ArbitraryPrecisionFloat/PMArbitraryPrecisionFloatTest.class.st b/src/Math-Tests-ArbitraryPrecisionFloat/PMArbitraryPrecisionFloatTest.class.st index 7ad66bc09..4b53a364c 100644 --- a/src/Math-Tests-ArbitraryPrecisionFloat/PMArbitraryPrecisionFloatTest.class.st +++ b/src/Math-Tests-ArbitraryPrecisionFloat/PMArbitraryPrecisionFloatTest.class.st @@ -418,7 +418,11 @@ PMArbitraryPrecisionFloatTest >> testCosh [ { #category : #'testing-arithmetic' } PMArbitraryPrecisionFloatTest >> testDivide [ | serie | - serie := {1. 2. 3. 5. 6. 7. 9. 10. 11. 12. 19. 243. 10 raisedTo: Float precision + 1. Float precision factorial. Float pi.}. + serie := #(1 2 3 5 6 7 9 10 11 12 19 243) asOrderedCollection + add: (10 raisedTo: Float precision + 1); + add: Float precision factorial; + add: Float pi; + asArray. serie do: [:num | | nf na | nf := num asFloat. diff --git a/src/Math-Tests-AutomaticDifferenciation/PMGradientAndHessianTest.class.st b/src/Math-Tests-AutomaticDifferenciation/PMGradientAndHessianTest.class.st index 33b7ca7be..1595eaf5d 100644 --- a/src/Math-Tests-AutomaticDifferenciation/PMGradientAndHessianTest.class.st +++ b/src/Math-Tests-AutomaticDifferenciation/PMGradientAndHessianTest.class.st @@ -16,13 +16,7 @@ PMGradientAndHessianTest >> test [ h := PMHessian of: f. r := #(0 0). self assert: (g value: #(0 -2)) equals: r. - self - assert: - (g - value: - {1. - (-3 / 2)}) - equals: r. + self assert: (g value: (Array with: 1 with: (-3 / 2))) equals: r. self assert: (g value: #(-4 6)) equals: r. self assert: (h value: #(0 -2)) diff --git a/src/Math-Tests-FunctionFit/PMAnotherChromosomeManagerTest.class.st b/src/Math-Tests-FunctionFit/PMAnotherChromosomeManagerTest.class.st index 9a5ed0d14..8977402eb 100644 --- a/src/Math-Tests-FunctionFit/PMAnotherChromosomeManagerTest.class.st +++ b/src/Math-Tests-FunctionFit/PMAnotherChromosomeManagerTest.class.st @@ -192,7 +192,7 @@ PMAnotherChromosomeManagerTest >> testnumberOfHamersleyPoints [ numberOfHamersleyPoints: 9 dimension: 1 randomized: false) - equals: ((1 to: 9) collect: [ :i | {(i * (1 / 9))} ]). + equals: ((1 to: 9) collect: [ :i | Array with: i * (1 / 9) ]). self assert: (PMAnotherChromosomeManager @@ -200,42 +200,17 @@ PMAnotherChromosomeManagerTest >> testnumberOfHamersleyPoints [ dimension: 4 randomized: false) equals: - {{(1 / 9). - (1 / 2). - (1 / 3). - (1 / 5)}. - {(2 / 9). - (1 / 4). - (2 / 3). - (2 / 5)}. - {(1 / 3). - (3 / 4). - (1 / 9). - (3 / 5)}. - {(4 / 9). - (1 / 8). - (4 / 9). - (4 / 5)}. - {(5 / 9). - (5 / 8). - (7 / 9). - (1 / 25)}. - {(2 / 3). - (3 / 8). - (2 / 9). - (6 / 25)}. - {(7 / 9). - (7 / 8). - (5 / 9). - (11 / 25)}. - {(8 / 9). - (1 / 16). - (8 / 9). - (16 / 25)}. - {1. - (9 / 16). - (1 / 27). - (21 / 25)}}. + (OrderedCollection new + add: (Array with: (1 / 9) with: (1 / 2) with: (1 / 3) with: (1 / 5)); + add: (Array with: (2 / 9) with: (1 / 4) with: (2 / 3) with: (2 / 5)); + add: (Array with: (1 / 3) with: (3 / 4) with: (1 / 9) with: (3 / 5)); + add: (Array with: (4 / 9) with: (1 / 8) with: (4 / 9) with: (4 / 5)); + add: (Array with: (5 / 9) with: (5 / 8) with: (7 / 9) with: (1 / 25)); + add: (Array with: (2 / 3) with: (3 / 8) with: (2 / 9) with: (6 / 25)); + add: (Array with: (7 / 9) with: (7 / 8) with: (5 / 9) with: (11 / 25)); + add: (Array with: (8 / 9) with: (1 / 16) with: (8 / 9) with: (16 / 25)); + add: (Array with: 1 with: (9 / 16) with: (1 / 27) with: (21 / 25)); + asArray). rand := (PMAnotherChromosomeManager numberOfHamersleyPoints: 3 dimension: 4 diff --git a/src/Math-Tests-FunctionFit/PMAnotherGeneticOptimizerTest.class.st b/src/Math-Tests-FunctionFit/PMAnotherGeneticOptimizerTest.class.st index e56a0f6c7..ceaf580e9 100644 --- a/src/Math-Tests-FunctionFit/PMAnotherGeneticOptimizerTest.class.st +++ b/src/Math-Tests-FunctionFit/PMAnotherGeneticOptimizerTest.class.st @@ -146,17 +146,9 @@ PMAnotherGeneticOptimizerTest >> testaddPointAt [ b := go bestPoints. self assert: b first position equals: #(0 1 0). self assert: b first value equals: 1. - go - addPointAt: - {0. - Float nan. - 0}. + go addPointAt: (Array with: 0 with: Float nan with: 0). self assert: go bestPoints equals: b. - go - addPointAt: - {(0 - Float infinity). - 0. - 0}. + go addPointAt: (Array with: (0 - Float infinity) with: 0 with: 0). self assert: go bestPoints equals: b. go addPointAt: #(1 1 0). b := go bestPoints. diff --git a/src/Math-Tests-FunctionFit/PMErrorOfParameterFunctionTest.class.st b/src/Math-Tests-FunctionFit/PMErrorOfParameterFunctionTest.class.st index b74ebc115..8f24bfdfa 100644 --- a/src/Math-Tests-FunctionFit/PMErrorOfParameterFunctionTest.class.st +++ b/src/Math-Tests-FunctionFit/PMErrorOfParameterFunctionTest.class.st @@ -26,17 +26,11 @@ PMErrorOfParameterFunctionTest >> testErrorCollection [ f errorType: #squared. self assert: (f errorCollection: #(0 1)) - equals: - {(1 / 4). - (4 / 9). - (9 / 16)}. + equals:(Array with: (1 / 4) with: (4 / 9) with: (9 / 16)). f errorType: #abs. self assert: (f errorCollection: #(0 1)) - equals: - {(1 / 2). - (2 / 3). - (3 / 4)}. + equals:(Array with: (1 / 2) with: (2 / 3) with: (3 / 4)). f errorType: #median. self assert: (f errorCollection: #(1 1)) equals: #(0 0 0) ] @@ -64,7 +58,7 @@ PMErrorOfParameterFunctionTest >> testFunction [ PMErrorOfParameterFunctionTest >> testPrint [ |aStream s| aStream :=ReadWriteStream with:''. -f data:{(1@(1/2)). (2@(2/3)). (3@(3/4))} . +f data:(Array with: (1@(1/2)) with: (2@(2/3)) with: (3@(3/4))). f printOn: aStream . s :=aStream contents . self assert: (s includesSubstring: 'a * x / (b + x)'). @@ -87,9 +81,7 @@ PMErrorOfParameterFunctionTest >> testQuartile [ PMErrorOfParameterFunctionTest >> testRealValue [ f := PMErrorOfParameterFunction function: [ :i :a | i + a ] - data: - {(1 @ 1). - (2 @ 2)}. + data: (Array with: 1 @ 1 with: 2 @ 2). f errorType: #squared. self assert: (f realValue: #(-2)) equals: 2. f errorType: #abs. diff --git a/src/Math-Tests-FunctionFit/PMGeneralFunctionFitTest.class.st b/src/Math-Tests-FunctionFit/PMGeneralFunctionFitTest.class.st index 76cd27cce..2086b78e7 100644 --- a/src/Math-Tests-FunctionFit/PMGeneralFunctionFitTest.class.st +++ b/src/Math-Tests-FunctionFit/PMGeneralFunctionFitTest.class.st @@ -128,7 +128,7 @@ self assert: (s includesSubstring: '#(0.'). PMGeneralFunctionFitTest >> testRelativeError [ |r| f:=[ :x :a| a]. -col:={1@2. 2@6}. +col:=Array with: 1@2 with: 2@6. fit:=PMGeneralFunctionFit function: f data: col minimumValues: -6 maximumValues: 6 . fit populationSize: 10. r :=fit evaluate first . diff --git a/src/Math-Tests-KDTree/PMKDTreeTest.class.st b/src/Math-Tests-KDTree/PMKDTreeTest.class.st index 88e92915e..f69fdc7ec 100644 --- a/src/Math-Tests-KDTree/PMKDTreeTest.class.st +++ b/src/Math-Tests-KDTree/PMKDTreeTest.class.st @@ -45,24 +45,24 @@ PMKDTreeTest >> testBenchmark [ { #category : #tests } PMKDTreeTest >> testIndexedKDTree1Dimension [ -|m aVector aResult bResult | -m :=(rand next:200) collect: [:n| Array with: n]."1-dimensional data, just some numbers" -self initializeTreeWith: m as: false . -1 to: 11do:[:v|aVector :={1/ v asFloat }. - aResult :=stupid nnSearch: aVector i:3. "3 nearest numbers to aVector " - bResult :=m atAll: ((tree nnSearch: aVector i:3)collect: [:a|a first]). - self equalityTest: aResult and: bResult ] . -] + | m aVector aResult bResult | + m := (rand next: 200) collect: [:n | Array with: n]. "1-dimensional data, just some numbers" + self initializeTreeWith: m as: false. + 1 to: 11 do: [:v | aVector := Array with: 1 / v asFloat. + aResult := stupid nnSearch: aVector i: 3. "3 nearest numbers to aVector " + bResult := m atAll: ((tree nnSearch: aVector i: 3) collect: [:a | a first]). + self equalityTest: aResult and: bResult]. + ] { #category : #tests } PMKDTreeTest >> testIndexedKDTree4Dimensions [ -|m aVector aResult bResult| -m :=(1 to: 2000) collect: [:n| (rand next:4)-0.5]. "4-dimensional data" -self initializeTreeWith: m as: false . -50 timesRepeat: [aVector :=(rand next: 4)- 0.5. - aResult :=stupid nnSearch: aVector i:2. "2 nearest neighbours" - bResult :=m atAll: ((tree nnSearch: aVector i:2)collect: [:a|a first]). - self equalityTest: aResult and: bResult ] . + | m aVector aResult bResult | + m := (1 to: 2000) collect: [:n | (rand next: 4) - 0.5]. "4-dimensional data" + self initializeTreeWith: m as: false. + 50 timesRepeat: [aVector := (rand next: 4) - 0.5. + aResult := stupid nnSearch: aVector i: 2. "2 nearest neighbours" + bResult := m atAll: ((tree nnSearch: aVector i: 2)collect: [:a | a first]). + self equalityTest: aResult and: bResult]. ] @@ -86,37 +86,31 @@ PMKDTreeTest >> testIndexedKDTreeSimple [ 1 to: 20 do: [ :v | n := 1 / v. self - assert: - (aTree - nnSearch: - {n. - n} - i: 1) - equals: (bTree nnSearch: {n} i: 1) ] + assert: (aTree nnSearch: (Array with: n with: n) i: 1) + equals: (bTree nnSearch: (Array with: n) i: 1) ] ] { #category : #tests } PMKDTreeTest >> testKDTree1Dimension [ -|m aVector aResult bResult| -m :=(rand next:200) collect: [:n| Array with: n]."1-dimensional data, just some numbers" -self initializeTreeWith: m as: true . -1 to: 11do:[:v|aVector :={1/ v asFloat }. - aResult :=stupid nnSearch: aVector i:3. "3 nearest numbers to aVector " - bResult :=tree nnSearch: aVector i:3. - self equalityTest: aResult and: bResult ] . - -] + | m aVector aResult bResult | + m :=(rand next: 200) collect: [:n | Array with: n]. "1-dimensional data, just some numbers" + self initializeTreeWith: m as: true . + 1 to: 11 do: [:v | aVector := Array with: 1 / v asFloat. + aResult := stupid nnSearch: aVector i: 3. "3 nearest numbers to aVector " + bResult := tree nnSearch: aVector i: 3. + self equalityTest: aResult and: bResult]. + ] { #category : #tests } PMKDTreeTest >> testKDTree1DimensionIntegers [ -|m aVector aResult bResult| -m :=(1 to: 20) collect: [:index | Array with: (rand nextInt: 10)]. "only integers, obviously with multiples. test distances because the nearest neighbours are not necessarily the same" -self initializeTreeWith: m as: true . -0 to: 11do:[:v|aVector :={v}. - aResult :=(aVector first - (stupid nnSearch: aVector i:3))abs. "distances between 3 nearest numbers and aVector " - bResult :=(aVector first - (tree nnSearch: aVector i:3))abs. "distances using KDTree" - self equalityTest: aResult and: bResult ] . -] + | m aVector aResult bResult | + m := (1 to: 20) collect: [:index | Array with: (rand nextInt: 10)]. "only integers, obviously with multiples. test distances because the nearest neighbours are not necessarily the same" + self initializeTreeWith: m as: true. + 0 to: 11 do:[:v | aVector := Array with: v. + aResult :=(aVector first - (stupid nnSearch: aVector i: 3)) abs. "distances between 3 nearest numbers and aVector " + bResult :=(aVector first - (tree nnSearch: aVector i: 3)) abs. "distances using KDTree" + self equalityTest: aResult and: bResult ] . + ] { #category : #tests } PMKDTreeTest >> testKDTree2Dimensions [ @@ -159,20 +153,14 @@ PMKDTreeTest >> testPMVectorCompatibility [ ifNil: [ ^ self skip: 'necessary PM package not loaded' ]. aVector := #(0) asPMVector. bVector := #(-2.0) asPMVector. - r := {aVector. - #(-5.0) asPMVector. - bVector} asPMVector. + r := (Array with: aVector with: #(-5.0) asPMVector with: bVector) asPMVector. self initializeTreeWith: r as: true. self assert: (tree nnSearch: bVector i: 2) - equals: - {bVector. - aVector}. + equals: (Array with: bVector with: aVector). self assert: (stupid nnSearch: bVector i: 2) - equals: - {bVector. - aVector}. + equals: (Array with: bVector with: aVector). self initializeTreeWith: r as: false. r := tree nnSearch: bVector i: 2. self assert: r first equals: #(3 0.0). diff --git a/src/Math-Tests-KDTree/PMNNStoreTest.class.st b/src/Math-Tests-KDTree/PMNNStoreTest.class.st index 0aa4019ae..e00d6bb97 100644 --- a/src/Math-Tests-KDTree/PMNNStoreTest.class.st +++ b/src/Math-Tests-KDTree/PMNNStoreTest.class.st @@ -74,12 +74,10 @@ PMNNStoreTest >> testExtremeCase [ n add: #(1 1). "adding should also always be possible, although it will not be added in this case" self deny: n maxDistance = 1. n - add: - {(0 - Float infinity). - 1}. "and this extreme case too." + add: (Array with: (0 - Float infinity) with: 1). "and this extreme case too." self assert: n isEmpty. self assert: n data equals: #(). - self should: [ n add: {nil . 1} ] raise: Error "but this should always raise an error (not only in NNStores with size 0), also in subclasses, otherwise one can have strange bugs" + self should: [ n add: (Array with: nil with: 1) ] raise: Error "but this should always raise an error (not only in NNStores with size 0), also in subclasses, otherwise one can have strange bugs" ] { #category : #tests } @@ -183,7 +181,7 @@ PMNNStoreTest >> testWithAll [ n sortFor: nil. "calling sortFor: is necessary with withAll:" self assert: n data equals: #(2 4 5). self assert: n isFull. - n add: {3 . 6}. "one has to be a bit carefull when one uses + n add: #(3 6). "one has to be a bit carefull when one uses NNStore withAll:, as sortfor: changes this data. n add: #(3 6) is not possible here!" self assert: n data equals: #(2 6 4). diff --git a/src/Math-Tests-Matrix/PMMatrixTest.class.st b/src/Math-Tests-Matrix/PMMatrixTest.class.st index 32a26fd66..0714ac672 100644 --- a/src/Math-Tests-Matrix/PMMatrixTest.class.st +++ b/src/Math-Tests-Matrix/PMMatrixTest.class.st @@ -238,7 +238,7 @@ PMMatrixTest >> testMatrixCloseToPrecision [ { #category : #comparing } PMMatrixTest >> testMatrixCos [ | a | - a := PMMatrix rows: {{Float pi. Float pi.}. {0. 0.}}. + a := PMMatrix rows: (Array with: (Array with: Float pi with: Float pi) with: #(0 0)). self assert: a cos equals: (PMMatrix rows:#((-1 -1) (1 1))) ] diff --git a/src/Math-Tests-Matrix/PMSingularValueDecompositionTest.class.st b/src/Math-Tests-Matrix/PMSingularValueDecompositionTest.class.st index d3f6d1b79..9a2797fa6 100644 --- a/src/Math-Tests-Matrix/PMSingularValueDecompositionTest.class.st +++ b/src/Math-Tests-Matrix/PMSingularValueDecompositionTest.class.st @@ -96,18 +96,21 @@ PMSingularValueDecompositionTest >> loadExample3 [ (-1 1 0) (0 -1 1)). - actualU := PMMatrix rows: { - { -1 / (2 sqrt) . 1 / (2 sqrt) } . - { 1 / (2 sqrt) . 1 / (2 sqrt) } }. + actualU := PMMatrix rows: ( + Array + with: (Array with: -1 / (2 sqrt) with: 1 / (2 sqrt)) + with: (Array with: 1 / (2 sqrt) with: 1 / (2 sqrt)) ). - actualV := PMMatrix rows: { - { 1 / (6 sqrt) . -1 / (2 sqrt) . 1 / (3 sqrt) } . - { -2 / (6 sqrt) . 0 . 1 / (3 sqrt) } . - { 1 / (6 sqrt) . 1 / (2 sqrt) . 1 / (3 sqrt) } }. + actualV := PMMatrix rows: ( + Array + with: (Array with: 1 / (6 sqrt) with: -1 / (2 sqrt) with: 1 / (3 sqrt)) + with: (Array with: -2 / (6 sqrt) with: 0 with: 1 / (3 sqrt)) + with: (Array with: 1 / (6 sqrt) with: 1 / (2 sqrt) with: 1 / (3 sqrt)) ). - actualS := PMMatrix rows: { - { 3 sqrt . 0 . 0} . - {0 . 1 . 0}}. + actualS := PMMatrix rows: ( + Array + with: (Array with: 3 sqrt with: 0 with: 0) + with: (Array with: 0 with: 1 with: 0) ). ] { #category : #'as yet unclassified' } @@ -126,18 +129,20 @@ PMSingularValueDecompositionTest >> loadExample4 [ (0 0 0 -1) (1 0 0 0)). - actualV := PMMatrix rows: { - { 0 . 0 . 0.2 sqrt . 0 . -1 * (0.8 sqrt) } . - { 1 . 0 . 0 . 0 . 0 } . - { 0 . 1 . 0 . 0 . 0 } . - { 0 . 0 . 0 . 1 . 0 } . - { 0 . 0 . 0.8 sqrt . 0 . 0.2 sqrt } }. + actualV := PMMatrix rows: (Array + with: ( Array with: 0 with: 0 with: 0.2 sqrt with: 0 with: -1 * (0.8 sqrt)) + with: ( Array with: 1 with: 0 with: 0 with: 0 with: 0) + with: ( Array with: 0 with: 1 with: 0 with: 0 with: 0) + with: ( Array with: 0 with: 0 with: 0 with: 1 with: 0) + with: ( Array with: 0 with: 0 with: 0.8 sqrt with: 0 with: 0.2 sqrt) + ). - actualS := PMMatrix rows: { - { 2 . 0 . 0 . 0 . 0 } . - { 0 . 3 . 0 . 0 . 0 } . - { 0 . 0 . 5 sqrt . 0 . 0 } . - { 0 . 0 . 0 . 0 . 0 } }. + actualS := PMMatrix rows: (Array + with: (Array with: 2 with: 0 with: 0 with: 0 with: 0) + with: (Array with: 0 with: 3 with: 0 with: 0 with: 0) + with: (Array with: 0 with: 0 with: 5 sqrt with: 0 with: 0) + with: (Array with: 0 with: 0 with: 0 with: 0 with: 0) + ) ] { #category : #initialization } diff --git a/src/Math-Tests-Numerical/PMGeneticOptimizerBugsTest.class.st b/src/Math-Tests-Numerical/PMGeneticOptimizerBugsTest.class.st index 9cb5b3700..783218ace 100644 --- a/src/Math-Tests-Numerical/PMGeneticOptimizerBugsTest.class.st +++ b/src/Math-Tests-Numerical/PMGeneticOptimizerBugsTest.class.st @@ -33,7 +33,7 @@ PMGeneticOptimizerBugsTest >> testBug2 [ | r | optimizer addPointAt: #(2 3). "i add a nan by hand here,which in a way doesnt make sense, just to get a nan result for function, but with a more complicated function it is perfectly possible for the optimizer to produce nan's by itself!" -optimizer addPointAt: {Float nan. 3}. +optimizer addPointAt: (Array with: Float nan with: 3). "if you inspect r here you will see that a _single nan result can _completely throw off the ga calculations" r:=optimizer randomScale. self deny: r first isNaN. diff --git a/src/Math-Tests-Permutation/PMPermutationTest.class.st b/src/Math-Tests-Permutation/PMPermutationTest.class.st index 8cc584cc0..2e54a1890 100644 --- a/src/Math-Tests-Permutation/PMPermutationTest.class.st +++ b/src/Math-Tests-Permutation/PMPermutationTest.class.st @@ -11,7 +11,7 @@ PMPermutationTest >> testAllOfSize [ self assert: (PMPermutation allOfSize: 0) equals: #(). self assert: (PMPermutation allOfSize: 1) - equals: {(PMPermutation identity: 1)}. + equals: (Array with: (PMPermutation identity: 1)). "odd" p := PMPermutation allOfSize: 3. self assert: p size equals: 3 factorial. @@ -122,19 +122,25 @@ PMPermutationTest >> testFromCycles [ { #category : #'class tests' } PMPermutationTest >> testGenerator [ |g c| -g:=PMPermutation generator: {PMPermutation size: 7 shift: 2}. +g:=PMPermutation generator: (Array with: (PMPermutation size: 7 shift: 2)). g do:[:p|self assert: p class equals:PMPermutation]. self assert: g size equals: 7. self assert: (g includes: (PMPermutation identity: 7)) . -g:=PMPermutation generator: {PMPermutation size: 6 shift: 2. (PMPermutation identity: 6)reverse}. +g:=PMPermutation generator: (Array + with: (PMPermutation size: 6 shift: 2) + with: (PMPermutation identity: 6)reverse). self assert: g size equals: 6. self assert: (g includes: (PMPermutation identity: 6)) . -g:=PMPermutation generator: { PMPermutation fromCycles: #((2 3 4 5)).PMPermutation fromCycles: #((1 2))}. +g:=PMPermutation generator: (Array + with: (PMPermutation fromCycles: #((2 3 4 5))) + with: (PMPermutation fromCycles: #((1 2)))). c:=(PMPermutation allOfSize: 5). self assert: g asSet equals: c asSet. self assert: g size equals: c size. -g:=PMPermutation generator: { PMPermutation fromCycles: #((3 4 5)).PMPermutation fromCycles: #((1 2 3))}. +g:=PMPermutation generator: (Array + with: (PMPermutation fromCycles: #((3 4 5))) + with: (PMPermutation fromCycles: #((1 2 3)))). c:=c select:[:p|p even]. self assert: g asSet equals: c asSet. self assert: g size equals: c size. diff --git a/src/Math-Tests-PrincipalComponentAnalysis/PMStandardizationScalerTest.class.st b/src/Math-Tests-PrincipalComponentAnalysis/PMStandardizationScalerTest.class.st index 03c4a34fa..06e58fad8 100644 --- a/src/Math-Tests-PrincipalComponentAnalysis/PMStandardizationScalerTest.class.st +++ b/src/Math-Tests-PrincipalComponentAnalysis/PMStandardizationScalerTest.class.st @@ -10,7 +10,7 @@ PMStandardizationScalerTest >> testMean [ aMatrix := PMMatrix rows: #((0.0 0.0) #(0.0 0.0) #(1.0 1.0) #(1.0 1.0)). t := PMStandardizationScaler new. t fit: aMatrix. - self assert: t mean asArray closeTo: #(0.5 0.5) + self assert: t mean closeTo: #(0.5 0.5) ] { #category : #tests } @@ -19,7 +19,7 @@ PMStandardizationScalerTest >> testScale [ aMatrix := PMMatrix rows: #((0.0 0.0) #(0.0 0.0) #(1.0 1.0) #(1.0 1.0)). t := PMStandardizationScaler new. t fit: aMatrix. - self assert: t scale asArray closeTo: #(0.5 0.5) + self assert: t scale asPMVector closeTo: #(0.5 0.5) ] { #category : #tests } @@ -54,7 +54,7 @@ PMStandardizationScalerTest >> testVariance [ aMatrix := PMMatrix rows: #((0.0 0.0) #(0.0 0.0) #(1.0 1.0) #(1.0 1.0)). t := PMStandardizationScaler new. t fit: aMatrix. - self assert: t variance asArray closeTo: #(0.25 0.25) + self assert: t variance asPMVector closeTo: #(0.25 0.25) ] { #category : #tests } @@ -66,5 +66,5 @@ PMStandardizationScalerTest >> testZeroScale [ aMatrix := PMMatrix rows: #((8.0 0.0) #(8.0 0.0) #(8.0 1.0) #(8.0 1.0)). t := PMStandardizationScaler new. t fit: aMatrix. - self assert: t scale asArray closeTo: #(1.0 0.5) + self assert: t scale asPMVector closeTo: #(1.0 0.5) ] diff --git a/src/Math-Tests-Quantile/PMQuantileTest.class.st b/src/Math-Tests-Quantile/PMQuantileTest.class.st index 5f396e795..e2bd8f08e 100644 --- a/src/Math-Tests-Quantile/PMQuantileTest.class.st +++ b/src/Math-Tests-Quantile/PMQuantileTest.class.st @@ -30,11 +30,7 @@ PMQuantileTest >> setUp [ c := #(1 3 2 4 5) asSortedCollection. d := #(1 3 2 4 5 6) asSortedCollection. b := #(2 4 5 7 8 9 10 12 15 16 18) asSortedCollection. - q := {0. - (1 / 4). - (1 / 2). - (3 / 4). - 1} + q := Array with: 0 with: (1 / 4) with: (1 / 2) with: (3 / 4) with: 1 ] { #category : #tests } @@ -58,11 +54,7 @@ PMQuantileTest >> testExtremeCase [ assert: (a quantile: 0 - withProbs: - {0.5. - 0.5. - (1 / 2). - (1 / 2)}) + withProbs: (Array with: 0.5 with: 0.5 with: (1 / 2) with: (1 / 2))) equals: 1 ] @@ -70,12 +62,7 @@ PMQuantileTest >> testExtremeCase [ PMQuantileTest >> testQuantileA [ self assert: (self resultCollect: a method: #modeBased) - equals: - {1. - (7 / 4). - (5 / 2). - (13 / 4). - 4}. + equals: (Array with: 1 with: (7 / 4) with: (5 / 2) with: (13 / 4) with: 4). self assert: (self resultCollect: a method: #inverseCDF) equals: #(1 1 2 3 4). @@ -87,36 +74,16 @@ PMQuantileTest >> testQuantileA [ equals: #(1 1 2 3 4). self assert: (self resultCollect: a method: #hydrologist) - equals: - {1. - (3 / 2). - (5 / 2). - (7 / 2). - 4}. + equals: (Array with: 1 with: (3 / 2) with: (5 / 2) with: (7 / 2) with: 4). self assert: (self resultCollect: a method: #weibull) - equals: - {1. - (5 / 4). - (5 / 2). - (15 / 4). - 4}. + equals: (Array with: 1 with: (5 / 4) with: (5 / 2) with: (15 / 4) with: 4). self assert: (self resultCollect: a method: #medianBased) - equals: - {1. - (17 / 12). - (5 / 2). - (43 / 12). - 4}. + equals: (Array with: 1 with: (17 / 12) with: (5 / 2) with: (43 / 12) with: 4). self assert: (self resultCollect: a method: #normalDistribution) - equals: - {1. - (23 / 16). - (5 / 2). - (57 / 16). - 4}. + equals: (Array with: 1 with: (23 / 16) with: (5 / 2) with: (57 / 16) with: 4). self assert: (a quantile: 1 / 4) equals: 7 / 4. self assert: a interQuartileRange equals: 2 ] @@ -127,12 +94,7 @@ PMQuantileTest >> testQuantileB [ self assert: (self resultCollect: b method: #modeBased) - equals: - {2. - 6. - 9. - (27 / 2). - 18}. + equals: (Array with: 2 with: 6 with: 9 with: (27 / 2) with: 18). self assert: (self resultCollect: b method: #inverseCDF) equals: #(2 5 9 15 18). @@ -141,39 +103,19 @@ PMQuantileTest >> testQuantileB [ equals: #(2 5 9 12 18). self assert: (self resultCollect: b method: #california) - equals: - {2. - (19 / 4). - (17 / 2). - (51 / 4). - 18}. + equals: (Array with: 2 with: (19 / 4) with: (17 / 2) with: (51 / 4) with: 18). self assert: (self resultCollect: b method: #hydrologist) - equals: - {2. - (11 / 2). - 9. - (57 / 4). - 18}. + equals: (Array with: 2 with: (11 / 2) with: 9 with: (57 / 4) with: 18). self assert: (self resultCollect: b method: #weibull) equals: #(2 5 9 15 18). self assert: (self resultCollect: b method: #medianBased) - equals: - {2. - (16 / 3). - 9. - (29 / 2). - 18}. + equals: (Array with: 2 with: (16 / 3) with: 9 with: (29 / 2) with: 18). self assert: (self resultCollect: b method: #normalDistribution) - equals: - {2. - (43 / 8). - 9. - (231 / 16). - 18}. + equals: (Array with: 2 with: (43 / 8) with: 9 with: (231 / 16) with: 18). self assert: (b quantile: 1 / 4) equals: 6. self assert: b interQuartileRange equals: 35 / 4 ] @@ -194,41 +136,17 @@ PMQuantileTest >> testQuantileC [ equals: #(1 1 3 4 5). self assert: (self resultCollect: c method: #california) - equals: - {1. - (5 / 4). - (5 / 2). - (15 / 4). - 5}. + equals: (Array with: 1 with: (5 / 4) with: (5 / 2) with: (15 / 4) with: 5). self assert: (self resultCollect: c method: #hydrologist) - equals: - {1. - (7 / 4). - 3. - (17 / 4). - 5}. + equals: (Array with: 1 with: (7 / 4) with: 3 with: (17 / 4) with: 5). self assert: (self resultCollect: c method: #weibull) - equals: - {1. - (3 / 2). - 3. - (9 / 2). - 5}. + equals: (Array with: 1 with: (3 / 2) with: 3 with: (9 / 2) with: 5). self assert: (self resultCollect: c method: #medianBased) - equals: - {1. - (5 / 3). - 3. - (13 / 3). - 5}. - r := {1. - (27 / 16). - 3. - (69 / 16). - 5}. + equals: (Array with: 1 with: (5 / 3) with: 3 with: (13 / 3) with: 5). + r := Array with: 1 with: (27 / 16) with: 3 with: (69 / 16) with: 5. self assert: (self resultCollect: c method: #normalDistribution) equals: r. @@ -236,11 +154,7 @@ PMQuantileTest >> testQuantileC [ assert: (self resultCollect: c - withProbs: - {(3 / 8). - (1 / 4). - 0. - 1}) + withProbs: (Array with: (3 / 8) with: (1 / 4) with: 0 with: 1)) equals: r. self assert: c interQuartileRange equals: 5 / 2 ] @@ -251,12 +165,7 @@ PMQuantileTest >> testQuantileD [ self assert: (self resultCollect: d method: #modeBased) - equals: - {1. - (9 / 4). - (7 / 2). - (19 / 4). - 6}. + equals: (Array with: 1 with: (9 / 4) with: (7 / 2) with: (19 / 4) with: 6). self assert: (self resultCollect: d method: #inverseCDF) equals: #(1 2 3 5 6). @@ -265,43 +174,18 @@ PMQuantileTest >> testQuantileD [ equals: #(1 2 3 5 6). self assert: (self resultCollect: d method: #california) - equals: - {1. - (3 / 2). - 3. - (9 / 2). - 6}. + equals: (Array with: 1 with: (3 / 2) with: 3 with: (9 / 2) with: 6). self assert: (self resultCollect: d method: #hydrologist) - equals: - {1. - 2. - (7 / 2). - 5. - 6}. + equals: (Array with: 1 with: 2 with: (7 / 2) with: 5 with: 6). self assert: (self resultCollect: d method: #weibull) - equals: - {1. - (7 / 4). - (7 / 2). - (21 / 4). - 6}. + equals: (Array with: 1 with: (7 / 4) with: (7 / 2) with: (21 / 4) with: 6). self assert: (self resultCollect: d method: #medianBased) - equals: - {1. - (23 / 12). - (7 / 2). - (61 / 12). - 6}. + equals: (Array with: 1 with: (23 / 12) with: (7 / 2) with: (61 / 12) with: 6). self assert: (self resultCollect: d method: #normalDistribution) - equals: - {1. - (31 / 16). - (7 / 2). - (81 / 16). - 6}. + equals: (Array with: 1 with: (31 / 16) with: (7 / 2) with: (81 / 16) with: 6). self assert: d interQuartileRange equals: 3 ] diff --git a/src/Math-Tests-TSNE/PMTSNETest.class.st b/src/Math-Tests-TSNE/PMTSNETest.class.st index 322b5cc15..3c912d8fd 100644 --- a/src/Math-Tests-TSNE/PMTSNETest.class.st +++ b/src/Math-Tests-TSNE/PMTSNETest.class.st @@ -14,7 +14,10 @@ PMTSNETest >> testComputePValues [ t := (PMTSNE new) x: (PMMatrix rows: #(#(1 2 3) #(4 5 6) #(7 8 9))); perplexity: 30.0. - self assert: t computePValues closeTo: (PMMatrix rows: {{0. 2/3. 2/3.}. {2/3. 0. 2/3}. {2/3. 2/3. 0.}}) + self assert: t computePValues closeTo: (PMMatrix rows: (Array + with: (Array with: 0 with: 2/3 with: 2/3) + with: (Array with: 2/3 with: 0 with: 2/3) + with: (Array with: 2/3 with: 2/3 with: 0))) ] { #category : #tests } @@ -59,7 +62,7 @@ PMTSNETest >> testEntropyOfAndPRowWithBeta [ pVector := PMVector new: (distanceVector size). entropy := PMTSNE entropyOf: distanceVector andPRow: pVector withBeta: 2.0. self assert: entropy closeTo: 0.003020119571023052. - self assert: pVector closeTo: { 0.99966454 . 0.00000011 . 0.00033535 } asPMVector. + self assert: pVector closeTo: (Array with: 0.99966454 with: 0.00000011 with: 0.00033535) asPMVector. ]