Skip to content

Commit

Permalink
Merge pull request #103 from kaBeech/prepare-for-release
Browse files Browse the repository at this point in the history
Prepare for Version 1.0.1.2
  • Loading branch information
kaBeech authored Aug 22, 2024
2 parents 4c498da + f5ddf26 commit b0bf151
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 48 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,11 @@
## 1.0.1.1 -- 2024-08-22

* Make all pictures in README viewable on Hackage

## 1.0.1.2 -- 2024-08-22

* Include benchmarking results and README images in package

* Improve flow in README

* Cleanup code and documentation a bit
54 changes: 32 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ sorted list. These transformations provide opportunities to increase redundancy
for improved robustness and can be leveraged to include any further processing
we wish to do on the elements.






<figure>
<img src="./assets/images/deck_shuffle_chart_censored.svg "
alt="When sorting a randomly shuffled deck of cards, Quicksort makes
Expand All @@ -36,8 +41,8 @@ we wish to do on the elements.
- [Why?](#why)
- [But why would anyone care about this in the first
place?](#but-why-would-anyone-care-about-this-in-the-first-place)
- [Why Haskell?](#why-haskell)
- [What's a tensor?](#whats-a-tensor)
- [Why Haskell?](#why-haskell)
- [Project structure](#project-structure)
- [Algorithms overview](#algorithms-overview)
- [Tensort](#tensort)
Expand Down Expand Up @@ -123,27 +128,6 @@ As Ackley asserts, as a culture we have tended to prioritize correctness and
efficiency to the detriment of robustness. The rate of our technological
progression precludes us from continuing to do so.

### Why Haskell?

1. Tensort can involve a lot of recursion, which Haskell handles well

2. All the other benefits we get from using a purely functional language, such
as strict dependency management, which even the smartest among us sometimes
falter without:

<figure>
<img src="./assets/images/ackley_deps.png"
alt="Comment from Ackley in the Beyond Efficiency code about Perl
updates breaking their code">
<figcaption><i><a href="http://livingcomputation.com/robusort2.tar">
Source
</a></i></figcaption>
</figure>



3. [Obviously](https://www.youtube.com/shorts/LGZKXZQeEBg)

### What's a tensor?

If you want an in-depth explanation,
Expand Down Expand Up @@ -173,6 +157,27 @@ while giving its dimensions a specified maximum rank size to achieve the
densest possible cluster of short lists. This provides opportunities to add
processing tailored to suit the current goals while preserving time efficiency.

### Why Haskell?

1. Tensort can involve a lot of recursion, which Haskell handles well

2. All the other benefits we get from using a purely functional language, such
as strict dependency management, which even the smartest among us sometimes
falter without:

<figure>
<img src="./assets/images/ackley_deps.png"
alt="Comment from Ackley in the Beyond Efficiency code about Perl
updates breaking their code">
<figcaption><i><a href="http://livingcomputation.com/robusort2.tar">
Source
</a></i></figcaption>
</figure>



3. [Obviously](https://www.youtube.com/shorts/LGZKXZQeEBg)

## Project structure

- `src/` contains the Tensort library
Expand Down Expand Up @@ -989,6 +994,11 @@ considerations to keep in mind:
Now let's take a look at how everything compares. Here is a graph showing the
benchmarking results for average error score for our algorithms:






<figure>
<img src="./assets/images/deck_shuffle_chart_uncensored.svg"
alt="When sorting a randomly shuffled deck of cards, Quicksort makes
Expand Down
25 changes: 11 additions & 14 deletions src/Data/Tensort/Utils/Compose.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
-- | Module for creating Tensors from Bytes and Tensors
--
-- Functions ending in "B" are for sorting Bits in a base (non-recursive)
-- Tensort variant
--
-- Functions ending in "R" are for sorting Records when used in a recursive
-- Tensort variant
--
Expand Down Expand Up @@ -55,12 +58,12 @@ import Data.Tensort.Utils.Types
-- STensorsBit [([(0,3),(1,7)],ByteMem [[1,3],[5,7]]),([(0,4),(1,8)],ByteMem [[2,4],[6,8]])]
createInitialTensors :: TensortProps -> SBytes -> STensors
createInitialTensors tsProps (SBytesBit bytes) =
STensorsBit (createInitialTensorsBits tsProps bytes)
STensorsBit (createInitialTensorsB tsProps bytes)
createInitialTensors tsProps (SBytesRec recs) =
STensorsRec (createInitialTensorsRecs tsProps recs)
STensorsRec (createInitialTensorsR tsProps recs)

createInitialTensorsBits :: TensortProps -> [Byte] -> [Tensor]
createInitialTensorsBits tsProps bytes =
createInitialTensorsB :: TensortProps -> [Byte] -> [Tensor]
createInitialTensorsB tsProps bytes =
foldr acc [] (splitEvery (bytesize tsProps) bytes)
where
acc :: [Byte] -> [Tensor] -> [Tensor]
Expand All @@ -70,8 +73,8 @@ createInitialTensorsBits tsProps bytes =
(getTensorFromBytes (subAlgorithm tsProps) (SBytesBit byte))
]

createInitialTensorsRecs :: TensortProps -> [ByteR] -> [TensorR]
createInitialTensorsRecs tsProps bytesR =
createInitialTensorsR :: TensortProps -> [ByteR] -> [TensorR]
createInitialTensorsR tsProps bytesR =
foldr acc [] (splitEvery (bytesize tsProps) bytesR)
where
acc :: [ByteR] -> [TensorR] -> [TensorR]
Expand Down Expand Up @@ -252,12 +255,6 @@ getRegisterFromTensorsR tensorsR = acc tensorsR []
-- SBitBit 38
getTopBitFromTensorStack :: STensor -> SBit
getTopBitFromTensorStack (STensorBit tensor) =
getTopBitFromTensorStackB tensor
SBitBit (snd (last (fst tensor)))
getTopBitFromTensorStack (STensorRec tensorR) =
getTopBitFromTensorStackR tensorR

getTopBitFromTensorStackB :: Tensor -> SBit
getTopBitFromTensorStackB (register, _) = SBitBit (snd (last register))

getTopBitFromTensorStackR :: TensorR -> SBit
getTopBitFromTensorStackR (registerR, _) = SBitRec (snd (last registerR))
SBitRec (snd (last (fst tensorR)))
3 changes: 3 additions & 0 deletions src/Data/Tensort/Utils/Reduce.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
-- | This module provides functions to reduce a list of TensorStacks into a
-- more compact list of TensorStacks
--
-- Functions ending in "B" are for sorting Bits in a base (non-recursive)
-- Tensort variant
--
-- Functions ending in "R" are for sorting Records when used in a recursive
-- Tensort variant
--
Expand Down
21 changes: 12 additions & 9 deletions src/Data/Tensort/Utils/Render.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
-- | Module for rendering a sorted list of Bits from a list of TensorStacks
--
-- Functions ending in "B" are for sorting Bits in a base (non-recursive)
-- Tensort variant
--
-- Functions ending in "R" are for sorting Records when used in a recursive
-- Tensort variant
--
Expand Down Expand Up @@ -49,7 +52,7 @@ getSortedBitsFromTensorB subAlg tensorRaw = acc tensorRaw []
where
acc :: TensorStack -> [SBit] -> [SBit]
acc tensor sortedBits = do
let (nextBit, tensor') = removeTopBitFromTensor subAlg tensor
let (nextBit, tensor') = removeTopBitFromTensorB subAlg tensor
let nextBit' = SBitBit nextBit
if isNothing tensor'
then nextBit' : sortedBits
Expand All @@ -75,13 +78,13 @@ getSortedBitsFromTensorR subAlg tensorRaw = acc tensorRaw []

-- | ==== __Examples__
-- >>> import Data.Tensort.Subalgorithms.Bubblesort (bubblesort)
-- >>> removeTopBitFromTensor bubblesort ([(0,5),(1,7)],ByteMem [[1,5],[3,7]])
-- >>> removeTopBitFromTensorB bubblesort ([(0,5),(1,7)],ByteMem [[1,5],[3,7]])
-- (7,Just ([(1,3),(0,5)],ByteMem [[1,5],[3]]))
removeTopBitFromTensor :: SortAlg -> Tensor -> (Bit, Maybe Tensor)
removeTopBitFromTensor subAlg (register, memory) = do
removeTopBitFromTensorB :: SortAlg -> Tensor -> (Bit, Maybe Tensor)
removeTopBitFromTensorB subAlg (register, memory) = do
let topRecord = last register
let topAddress = fst topRecord
let (topBit, memory') = removeBitFromMemory subAlg memory topAddress
let (topBit, memory') = removeBitFromMemoryB subAlg memory topAddress
if isNothing memory'
then (topBit, Nothing)
else
Expand Down Expand Up @@ -113,8 +116,8 @@ removeTopBitFromTensorR subAlg (register, memory) = do
)
)

removeBitFromMemory :: SortAlg -> Memory -> Int -> (Bit, Maybe Memory)
removeBitFromMemory subAlg (ByteMem bytes) i = do
removeBitFromMemoryB :: SortAlg -> Memory -> Int -> (Bit, Maybe Memory)
removeBitFromMemoryB subAlg (ByteMem bytes) i = do
let topByte = bytes !! i
let topBit = last topByte
let topByte' = init topByte
Expand All @@ -131,9 +134,9 @@ removeBitFromMemory subAlg (ByteMem bytes) i = do
let topByte'' = fromSortBit (subAlg (SortBit topByte'))
let bytes' = take i bytes ++ [topByte''] ++ drop (i + 1) bytes
(topBit, Just (ByteMem bytes'))
removeBitFromMemory subAlg (TensorMem tensors) i = do
removeBitFromMemoryB subAlg (TensorMem tensors) i = do
let topTensor = tensors !! i
let (topBit, topTensor') = removeTopBitFromTensor subAlg topTensor
let (topBit, topTensor') = removeTopBitFromTensorB subAlg topTensor
if isNothing topTensor'
then do
let tensors' = take i tensors ++ drop (i + 1) tensors
Expand Down
9 changes: 6 additions & 3 deletions tensort.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ name: tensort
-- PVP summary: +-+------- breaking API changes
-- | | +----- non-breaking API additions
-- | | | +--- code changes with no API change
version: 1.0.1.1
version: 1.0.1.2

tested-with: GHC==9.8.2,
GHC==9.6.4,
Expand Down Expand Up @@ -77,10 +77,13 @@ build-type: Simple

-- Extra doc files to be distributed with the package, such as a CHANGELOG or a README.
extra-doc-files: README.md,
CHANGELOG.md
CHANGELOG.md,

-- Extra source files to be distributed with the package, such as examples, or a tutorial module.
-- extra-source-files:
extra-source-files: assets/images/*.png,
assets/images/*.svg,
data/WonkyComparator/*.txt,
data/WonkyStuckComparator/*.txt,

source-repository head
type: git
Expand Down

0 comments on commit b0bf151

Please sign in to comment.