Download as pdf or txt
Download as pdf or txt
You are on page 1of 45

Architecture of Advanced Numerical

Analysis Systems: Designing a


Scientific Computing System using
OCaml 1st Edition Liang Wang
Visit to download the full and correct content document:
https://ebookmass.com/product/architecture-of-advanced-numerical-analysis-systems
-designing-a-scientific-computing-system-using-ocaml-1st-edition-liang-wang/
More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Architecture of Advanced Numerical Analysis Systems:


Designing a Scientific Computing System using OCaml 1st
Edition Liang Wang

https://ebookmass.com/product/architecture-of-advanced-numerical-
analysis-systems-designing-a-scientific-computing-system-using-
ocaml-1st-edition-liang-wang-2/

Concise Guide to Numerical Algorithmics: The


Foundations and Spirit of Scientific Computing John
Lawrence Nazareth

https://ebookmass.com/product/concise-guide-to-numerical-
algorithmics-the-foundations-and-spirit-of-scientific-computing-
john-lawrence-nazareth/

System Architecture and Complexity Vol. 2: Contribution


of Systems of Systems to Systems Thinking Printz

https://ebookmass.com/product/system-architecture-and-complexity-
vol-2-contribution-of-systems-of-systems-to-systems-thinking-
printz/

Numerical Methods Using Kotlin: For Data Science,


Analysis, and Engineering 1st Edition Haksun Li

https://ebookmass.com/product/numerical-methods-using-kotlin-for-
data-science-analysis-and-engineering-1st-edition-haksun-li-2/
Numerical Methods Using Kotlin: For Data Science,
Analysis, and Engineering 1st Edition Haksun Li

https://ebookmass.com/product/numerical-methods-using-kotlin-for-
data-science-analysis-and-engineering-1st-edition-haksun-li/

Graph Database and Graph Computing for Power System


Analysis Renchang Dai

https://ebookmass.com/product/graph-database-and-graph-computing-
for-power-system-analysis-renchang-dai/

Battery System Modeling Shunli Wang

https://ebookmass.com/product/battery-system-modeling-shunli-
wang/

Cloud Computing: Concepts, Technology, Security &


Architecture Thomas Erl & Eric Barceló Monroy

https://ebookmass.com/product/cloud-computing-concepts-
technology-security-architecture-thomas-erl-eric-barcelo-monroy/

Ascend AI Processor Architecture and Programming:


Principles and Applications of CANN Xiaoyao Liang

https://ebookmass.com/product/ascend-ai-processor-architecture-
and-programming-principles-and-applications-of-cann-xiaoyao-
liang/
Architecture of
Advanced Numerical
Analysis Systems
Designing a Scientific Computing System
using OCaml

Liang Wang
Jianxin Zhao
Architecture of Advanced
Numerical Analysis
Systems
Designing a Scientific Computing
System using OCaml

Liang Wang
Jianxin Zhao
Architecture of Advanced Numerical Analysis Systems: Designing a Scientific Computing
System using OCaml

Liang Wang Jianxin Zhao


Helsinki, Finland Bejing, China

ISBN-13 (pbk): 978-1-4842-8852-8 ISBN-13 (electronic): 978-1-4842-8853-5


https://doi.org/10.1007/978-1-4842-8853-5

Copyright © 2023 by Liang Wang, Jianxin Zhao


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is
concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on
microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation,
computer software, or by similar or dissimilar methodology now known or hereafter developed.
Open Access This book is licensed under the terms of the Creative Commons Attribution 4.0
International License (http://creativecommons.org/licenses/by/4.0/), which permits use, sharing,
adaptation, distribution and reproduction in any medium or format, as long as you give appropriate
credit to the original author(s) and the source, provide a link to the Creative Commons license and indicate if changes
were made.
The images or other third party material in this book are included in the book’s Creative Commons license, unless
indicated otherwise in a credit line to the material. If material is not included in the book’s Creative Commons license and
your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain
permission directly from the copyright holder.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every
occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to
the benefit of the trademark owner, with no intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as
such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication, neither the
authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made.
The publisher makes no warranty, express or implied, with respect to the material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Steve Anglin
Development Editor: James Markham
Coordinating Editor: Mark Powers
Cover designed by eStudioCalamar
Cover image by Lukasz Niescioruk on Unsplash (www.unsplash.com)
Distributed to the book trade worldwide by Apress Media, LLC, 1 New York Plaza, New York, NY 10004, U.S.A. Phone
1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress
Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM
Finance Inc). SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail booktranslations@springernature.com; for reprint, paperback, or audio
rights, please e-mail bookpermissions@springernature.com.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also
available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.
com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub
(https://github.com/Apress). For more detailed information, please visit http://www.apress.com/source-code.
Printed on acid-free paper
To my wife Maria, our daughters Matilda and Sofia,
and my beloved family.
—Liang
To my parents and sister; to their unyielding love and support.
To all those who are fighting for freedom and righteousness against the
unleashing evil from hell.
“Namárië, ar nai aistalë Eldar ar Atani ar ilyë Léralieron hilya le. Eleni
sílar antalyannar.”
—Jianxin
Table of Contents
About the Authors���������������������������������������������������������������������������������������������������� xi

Acknowledgments������������������������������������������������������������������������������������������������� xiii

Chapter 1: Introduction�������������������������������������������������������������������������������������������� 1
1.1 Numerical Computing in OCaml���������������������������������������������������������������������������������������������� 1
1.2 Architecture����������������������������������������������������������������������������������������������������������������������������� 3
Basic Computing and Analytics with Owl�������������������������������������������������������������������������������� 4
Advanced Design in Owl���������������������������������������������������������������������������������������������������������� 5
Hardware and Deployment������������������������������������������������������������������������������������������������������ 6
Research on Owl��������������������������������������������������������������������������������������������������������������������� 7
1.3 Summary�������������������������������������������������������������������������������������������������������������������������������� 8

Chapter 2: Core Optimizations���������������������������������������������������������������������������������� 9


2.1 N-Dimensional Array in Owl���������������������������������������������������������������������������������������������������� 9
2.2 Interface OCaml to C������������������������������������������������������������������������������������������������������������� 12
2.3 Core Optimization of Computation���������������������������������������������������������������������������������������� 15
CPU Support of Parallel Computing��������������������������������������������������������������������������������������� 17
Vectorization�������������������������������������������������������������������������������������������������������������������������� 17
Memory��������������������������������������������������������������������������������������������������������������������������������� 21
2.4 Optimization Techniques������������������������������������������������������������������������������������������������������� 26
Hardware Parallelization������������������������������������������������������������������������������������������������������� 26
Cache Optimization���������������������������������������������������������������������������������������������������������������� 27
Other Techniques������������������������������������������������������������������������������������������������������������������� 31
2.5 Example: Convolution������������������������������������������������������������������������������������������������������������ 32
2.6 Automated Empirical Optimization of Software�������������������������������������������������������������������� 42
2.7 Summary������������������������������������������������������������������������������������������������������������������������������ 47

v
Table of Contents

Chapter 3: Algorithmic Differentiation�������������������������������������������������������������������� 49


3.1 Introduction��������������������������������������������������������������������������������������������������������������������������� 49
Three Ways of Differentiating������������������������������������������������������������������������������������������������ 50
Architecture of Algodiff Module��������������������������������������������������������������������������������������������� 51
3.2 Types������������������������������������������������������������������������������������������������������������������������������������� 53
Forward and Reverse Modes������������������������������������������������������������������������������������������������� 54
Data Types����������������������������������������������������������������������������������������������������������������������������� 58
Operations on AD Type����������������������������������������������������������������������������������������������������������� 61
3.3 Operators������������������������������������������������������������������������������������������������������������������������������ 63
Calculation Rules������������������������������������������������������������������������������������������������������������������� 63
Generalize Rules into Builder Template��������������������������������������������������������������������������������� 66
3.4 API����������������������������������������������������������������������������������������������������������������������������������������� 70
Low-Level APIs���������������������������������������������������������������������������������������������������������������������� 70
High-Level APIs��������������������������������������������������������������������������������������������������������������������� 73
3.5 More Implementation Details������������������������������������������������������������������������������������������������ 76
Perturbation Confusion and Tag�������������������������������������������������������������������������������������������� 76
Lazy Evaluation���������������������������������������������������������������������������������������������������������������������� 77
Extending AD������������������������������������������������������������������������������������������������������������������������� 79
Graph Utility��������������������������������������������������������������������������������������������������������������������������� 80
3.6 How AD Is Built upon Ndarray����������������������������������������������������������������������������������������������� 81
3.7 Summary������������������������������������������������������������������������������������������������������������������������������ 85

Chapter 4: Mathematical Optimization������������������������������������������������������������������� 87


4.1 Gradient Descent������������������������������������������������������������������������������������������������������������������ 88
4.2 Components�������������������������������������������������������������������������������������������������������������������������� 89
Learning Rate������������������������������������������������������������������������������������������������������������������������ 90
Momentum���������������������������������������������������������������������������������������������������������������������������� 98
Batch����������������������������������������������������������������������������������������������������������������������������������� 100
Checkpoint��������������������������������������������������������������������������������������������������������������������������� 101
4.3 Gradient Descent Implementation�������������������������������������������������������������������������������������� 106

vi
Table of Contents

4.4 Regression�������������������������������������������������������������������������������������������������������������������������� 111


Linear Regression���������������������������������������������������������������������������������������������������������������� 112
Loss������������������������������������������������������������������������������������������������������������������������������������� 112
Implementation of Linear Regression���������������������������������������������������������������������������������� 113
Other Types of Regression��������������������������������������������������������������������������������������������������� 116
Regularization��������������������������������������������������������������������������������������������������������������������� 117
4.5 Summary���������������������������������������������������������������������������������������������������������������������������� 119

Chapter 5: Deep Neural Networks������������������������������������������������������������������������ 121


5.1 Module Architecture������������������������������������������������������������������������������������������������������������ 121
5.2 Neurons������������������������������������������������������������������������������������������������������������������������������� 123
Core Functions��������������������������������������������������������������������������������������������������������������������� 124
Activation Module���������������������������������������������������������������������������������������������������������������� 126
5.3 Networks����������������������������������������������������������������������������������������������������������������������������� 127
5.4 Training������������������������������������������������������������������������������������������������������������������������������� 130
Forward and Backward Pass����������������������������������������������������������������������������������������������� 131
5.5 Neural Network Compiler���������������������������������������������������������������������������������������������������� 133
5.6 Case Study: Object Detection���������������������������������������������������������������������������������������������� 138
Object Detection Network Architectures����������������������������������������������������������������������������� 140
Implementation of Mask R-CNN������������������������������������������������������������������������������������������ 142
5.7 Summary���������������������������������������������������������������������������������������������������������������������������� 147

Chapter 6: Computation Graph����������������������������������������������������������������������������� 149


6.1 The Definition of Computation Graph���������������������������������������������������������������������������������� 149
Dynamic Graph and Static Graph���������������������������������������������������������������������������������������� 150
Significance in Computing��������������������������������������������������������������������������������������������������� 152
6.2 Applications Inside the Computing System������������������������������������������������������������������������� 153
Basic Numerical Operations������������������������������������������������������������������������������������������������ 153
Algorithmic Differentiation with CGraph������������������������������������������������������������������������������ 155
Deep Neural Network���������������������������������������������������������������������������������������������������������� 158
6.3 Design of Computation Graph Module�������������������������������������������������������������������������������� 160
Computing Device��������������������������������������������������������������������������������������������������������������� 163

vii
Table of Contents

Types of Operation��������������������������������������������������������������������������������������������������������������� 166


Shape Inference������������������������������������������������������������������������������������������������������������������ 167
Creating and Linking Nodes������������������������������������������������������������������������������������������������ 169
Optimization of Graph Structure������������������������������������������������������������������������������������������ 173
Computation Engine������������������������������������������������������������������������������������������������������������ 180
6.4 Optimizing Memory Usage in Computation Graph�������������������������������������������������������������� 183
6.5 Summary���������������������������������������������������������������������������������������������������������������������������� 188

Chapter 7: Performance Accelerators������������������������������������������������������������������ 191


7.1 Hardware Accelerators�������������������������������������������������������������������������������������������������������� 191
Utilizing Accelerators����������������������������������������������������������������������������������������������������������� 193
7.2 Design��������������������������������������������������������������������������������������������������������������������������������� 194
Core Abstraction������������������������������������������������������������������������������������������������������������������ 195
Engines�������������������������������������������������������������������������������������������������������������������������������� 202
7.3 ONNX Engine����������������������������������������������������������������������������������������������������������������������� 202
Example 1: Basic Operations����������������������������������������������������������������������������������������������� 204
Example 2: Variable Initialization����������������������������������������������������������������������������������������� 205
Example 3: Neural Network������������������������������������������������������������������������������������������������� 206
7.4 LaTeX Engine����������������������������������������������������������������������������������������������������������������������� 208
7.5 Owl Engine�������������������������������������������������������������������������������������������������������������������������� 210
7.6 Summary���������������������������������������������������������������������������������������������������������������������������� 212

Chapter 8: Compiler Backends����������������������������������������������������������������������������� 215


8.1 Base Library������������������������������������������������������������������������������������������������������������������������ 215
8.2 Backend: JavaScript����������������������������������������������������������������������������������������������������������� 217
Native OCaml����������������������������������������������������������������������������������������������������������������������� 218
Facebook Reason���������������������������������������������������������������������������������������������������������������� 220
8.3 Backend: MirageOS������������������������������������������������������������������������������������������������������������� 221
Example: Gradient Descent������������������������������������������������������������������������������������������������� 221
Example: Neural Network���������������������������������������������������������������������������������������������������� 224
8.4 Evaluation��������������������������������������������������������������������������������������������������������������������������� 225
8.5 Summary���������������������������������������������������������������������������������������������������������������������������� 228

viii
Table of Contents

Chapter 9: Composition and Deployment������������������������������������������������������������� 229


9.1 Script Sharing with Zoo������������������������������������������������������������������������������������������������������ 229
Example������������������������������������������������������������������������������������������������������������������������������� 229
Version Control�������������������������������������������������������������������������������������������������������������������� 231
9.2 Service Deployment and Composition�������������������������������������������������������������������������������� 233
9.3 System Design�������������������������������������������������������������������������������������������������������������������� 235
Service�������������������������������������������������������������������������������������������������������������������������������� 236
Type Checking��������������������������������������������������������������������������������������������������������������������� 236
DSL�������������������������������������������������������������������������������������������������������������������������������������� 237
Service Discovery���������������������������������������������������������������������������������������������������������������� 238
9.4 Use Case����������������������������������������������������������������������������������������������������������������������������� 238
9.5 Discussion��������������������������������������������������������������������������������������������������������������������������� 239
9.6 Summary���������������������������������������������������������������������������������������������������������������������������� 240

Chapter 10: Distributed Computing���������������������������������������������������������������������� 243


10.1 Distributed Machine Learning������������������������������������������������������������������������������������������� 243
10.2 The Actor Distributed Engine��������������������������������������������������������������������������������������������� 245
Map-Reduce Engine������������������������������������������������������������������������������������������������������������ 245
Parameter Server Engine���������������������������������������������������������������������������������������������������� 246
Compose Actor with Owl����������������������������������������������������������������������������������������������������� 249
10.3 Synchronization: Barrier Control Methods������������������������������������������������������������������������ 252
10.4 System Design Space and Parameters����������������������������������������������������������������������������� 256
Compatibility������������������������������������������������������������������������������������������������������������������������ 260
10.5 Convergence Analysis������������������������������������������������������������������������������������������������������� 264
How Effective Is Sampling��������������������������������������������������������������������������������������������������� 266
Implementation Technique�������������������������������������������������������������������������������������������������� 268
10.6 Evaluation������������������������������������������������������������������������������������������������������������������������� 269
Experiment Setup���������������������������������������������������������������������������������������������������������������� 269
System Progress����������������������������������������������������������������������������������������������������������������� 272
Sampling Settings��������������������������������������������������������������������������������������������������������������� 275
10.7 Summary�������������������������������������������������������������������������������������������������������������������������� 278

ix
Table of Contents

Chapter 11: Testing Framework��������������������������������������������������������������������������� 281


11.1 Unit Test���������������������������������������������������������������������������������������������������������������������������� 281
11.2 Example���������������������������������������������������������������������������������������������������������������������������� 282
11.3 What Could Go Wrong�������������������������������������������������������������������������������������������������������� 287
Corner Cases����������������������������������������������������������������������������������������������������������������������� 287
Test Coverage���������������������������������������������������������������������������������������������������������������������� 288
11.4 Use Functor����������������������������������������������������������������������������������������������������������������������� 288
11.5 Performance Tests������������������������������������������������������������������������������������������������������������ 289
11.6 Summary�������������������������������������������������������������������������������������������������������������������������� 291

Appendix A: Basic Analytics Examples���������������������������������������������������������������� 293

Appendix B: System Conventions������������������������������������������������������������������������� 303

Appendix C: Metric Systems and Constants��������������������������������������������������������� 311

Appendix D: Algodiff Module�������������������������������������������������������������������������������� 325

Appendix E: Neural Network Module�������������������������������������������������������������������� 363

Appendix F: Actor System for Distributed Computing������������������������������������������ 423

Bibliography��������������������������������������������������������������������������������������������������������� 457

Index��������������������������������������������������������������������������������������������������������������������� 465

x
About the Authors
Liang Wang is the Chief AI Architect at Nokia, the Chief
Scientific Officer at iKVA, a Senior Researcher at the
University of Cambridge, and an Intel Software Innovator.
He has a broad research interest in artificial intelligence,
machine learning, operating systems, computer networks,
optimization theory, and graph theory.

Jianxin Zhao is a PhD graduate from the University of


Cambridge. His research interests include numerical
computation, artificial intelligence, decentralized systems,
and their application in the real world.

xi
Acknowledgments
Developing a full-featured numerical-analysis system is very complicated. Writing a
book to dive deep into its architecture is an even more challenging task. It not only
requires skills, enthusiasm, persistence, but also needs strong support from families,
colleagues, and communities. For years, we have received so much help from so many
individuals and organizations that it is almost impossible to make an exhaustive list.
Nonetheless, we would particularly like to emphasize that Owl is developed on top of
an enormous amount of previous work. Without the continuous efforts of these projects
and the intellectual contributions of these people over the years, it would be impossible
for us to create this system and deliver this book.
We give our most hearty thanks to those who contribute to the Owl project. Marcello
Seri and Ta-Chu Kao developed owl-ode, an Ordinary Differential Equation solver
library based on Owl. Pierre Vandenhove worked on the memory optimization of the
computation graph module during his internship at the OCaml Labs in Cambridge.
Tudor Tiplea participated in developing the base library in Owl so that it could run on
various backends such as browsers. Ben Catterall’s thesis work on the PSP provided a
theoretical foundation for the Actor system.
We would like to express our sincerest gratitude and appreciation to the OCaml
Software Foundation1 and Ahrefs2 for fully sponsoring this open access book as well
as their long-term support to the Owl project.

1
http://ocaml-sf.org/
2
https://ahrefs.com/

xiii
CHAPTER 1

Introduction
This book introduces Owl, a numerical library we have been developing and
maintaining for years. We develop Owl for scientific and engineering computing in the
OCaml language. It focuses on providing a comprehensive set of high-level numerical
functions so that developers can quickly build up any data analytical applications. Over
years of intensive development and continuous optimization, Owl has evolved into
a powerful software system with competitive performance compared to mainstream
numerical libraries. Meanwhile, Owl’s overall architecture remains simple and elegant.
Its small codebase can be easily managed by a small group of developers.
In this book, we are going to introduce the design and architecture of Owl, from
its designers’ perspective. The target audience is anyone who is interested in not only
how to use mathematical functions in numerical applications but also how they are
designed, organized, and implemented from scratch. Some prerequisites are needed
though. We assume the readers are familiar with basic syntax of the OCaml language.
We recommend [38] as a good reference book on this matter. Also note that this book
focuses on introducing core parts of the Owl codebase, such as the implementation
and design of various key modules. If you are more interested in how to use the
functionalities provided in Owl to solve numerical problems, such as basic mathematical
calculation, linear algebra, statistics, signal processing, etc., please refer to our book
OCaml Scientific Computing: Functional Programming in Data Science and Artificial
Intelligence [26].

1.1 Numerical Computing in OCaml


Scientific computing is a rapidly evolving multidisciplinary field that uses advanced
computing capabilities to understand and solve complex problems in the real world.
It is widely used in various fields in research and industry, for example, simulations in
biology and physics, weather forecasting, revenue optimization in finance, etc. One

1
© Liang Wang, Jianxin Zhao 2023
L. Wang and J. Zhao, Architecture of Advanced Numerical Analysis Systems,
https://doi.org/10.1007/978-1-4842-8853-5_1
Chapter 1 Introduction

most recent hot topic in scientific computing is machine learning. Thanks to the recent
advances in machine learning and deep neural networks, there is a huge demand on
various numerical tools and libraries in order to facilitate both academic researchers and
industrial developers to fast prototype and test their new ideas, then develop and deploy
analytical applications at a large scale.
Take deep neural networks as an example; Google invests heavily in TensorFlow,
while Facebook promotes their PyTorch. Beyond these libraries focusing on one
specific numerical task, the interest on general-purpose tools like Python and Julia
also grows fast. Python has been one popular choice among developers for fast
prototyping analytical applications. One important reason is SciPy and NumPy libraries,
tightly integrated with other advanced functionality such as plotting, offer a powerful
environment which lets developers write very concise code to finish complicated
numerical tasks. As a result, most frameworks provide Python bindings to take
advantage of the existing numerical infrastructure in NumPy and SciPy.
On the other hand, back before Owl was developed, the support of basic scientific
computing in OCaml was rather fragmented. There had been some initial efforts (e.g.,
Lacaml, Oml, Pareto, etc.), but their APIs were either too low level to offer satisfying
productivity or the designs overly focused on a specific problem domain. Moreover,
inconsistent data representation and excessive use of abstract types made it difficult to
exchange data across different libraries. Consequently, developers often had to write
a significant amount of boilerplate code just to finish rather trivial numerical tasks.
There was a severe lack of a general-purpose numerical library in the OCaml ecosystem.
However, we believe OCaml is a good candidate for developing such a general-purpose
numerical library for two important reasons:

• We can write functional code as concise as that in Python with


type-safety.

• OCaml code often has much superior performance compared to


dynamic languages such as Python and Julia.

2
Chapter 1 Introduction

1.2 Architecture
Designing and developing a full-fledged numerical library is a nontrivial task, despite
that OCaml has been widely used in system programming such as MirageOS. The key
difference between the two is fundamental and interesting: system libraries provide
a lean set of APIs to abstract complex and heterogeneous physical hardware, while
numerical libraries offer a fat set of functions over a small set of abstract number types.
When the Owl project started in 2016, we were immediately confronted by a series
of fundamental questions like: “what should be the basic data types”, “what should
be the core data structures”, “what modules should be designed”, etc. In the following
development and performance optimization, we also tackled many research and
engineering challenges on a wide range of different topics such as software engineering,
language design, system and network programming, etc. As a result, Owl is a rather
complex library, arguably one of the most complicated numerical software system
developed in OCaml. It contains about 269K lines of OCaml code, 142K lines of C code,
and more than 6500 functions. We have strived for a modular design to make sure that
the system is flexible and extendable.
We present the architecture of Owl briefly as in Figure 1-1. It contains two
subsystems. The subsystem on the left part is Owl’s numerical subsystem. The modules
contained in this subsystem fall into four categories:

• Core modules contain basic data structures, namely, the


n-dimensional array, including C-based and OCaml-based
implementation, and symbolic representation.

• Classic analytics contains basic mathematical and statistical


functions, linear algebra, signal processing, ordinary differential
equation, etc., and foreign function interface to other libraries (e.g.,
CBLAS and LAPACKE).

• Advanced analytics, such as algorithmic differentiation, optimization,


regression, neural network, natural language processing, etc.

• Service composition and deployment to multiple backends such as to


the browser, container, virtual machine, and other accelerators via a
computation graph.

3
Chapter 1 Introduction

Figure 1-1. The whole system can be divided into two subsystems. The subsystem
on the left deals with numerical computation, while the one on the right handles
the related tasks in a distributed and parallel computing context including
synchronization, scheduling, etc

In the rest of this chapter, we give a brief introduction about these various
components in Owl and set a road map for this book.

Basic Computing and Analytics with Owl


In a numerical library or software such as NumPy, MATLAB, TensorFlow, and Owl,
the N-dimensional array (ndarray) is the most fundamental data type for building
scientific computing applications. In most such applications, solely using scalar values
is insufficient. Both matrices and vectors are special cases of ndarray. Owl provides
the Ndarray module, the usability and performance of which are essential to the whole
architecture in Owl. In Chapter 2, we will introduce this module, including how it is
designed and its performance optimization.

4
Chapter 1 Introduction

Owl supports a wide variety of classic numerical analytics methods, including basic
mathematical functions, statistics, linear algebra, ordinary differential equation, and
signal processing. The functions in each field are included in a corresponding module.
Their design is similar to that of Ndarray module, which is mainly interfacing to existing
tools in C code, such as OpenBLAS. The Ndarray module partly relies on these functions,
especially the ones that operate on scalars. For example, Ndarray provides a sin function.
What it does is actually calling the scalar version sin function in the Maths module and
mapping them on all its elements. Since this book mainly focuses on the architectural
design of Owl, we will not introduce in detail how to apply Owl in these fields; instead,
we will briefly give some examples in Appendix A.

Advanced Design in Owl


We have introduced the various classic analytics fields that are supported in Owl. What
makes Owl more powerful are a series of advanced analytics. At the heart of them lies
algorithmic differentiation (AD), which will be introduced in Chapter 3. Performing
differentiation is so crucial to modern numerical applications that it is utilized almost
everywhere. Moreover, it is proven that AD provides both efficient and accurate
differentiation computations that are not affected by numerical errors.
One of the prominent analytics that benefit from the power of AD is optimization
(Chapter 4), which is about finding minima or maxima of a function. Though
optimization methods do not necessarily require computing differentiation, it is often a
key element in efficient optimization methods. One most commonly used optimization
method is gradient descent, which iteratively applies optimization on a complex object
function by small steps until it is minimized by some standard. It is exactly how another
type of advanced application, regression, works. Regression covers a variety of methods,
including linear regression, logistic regression, etc. Each can be applied to different
scenarios and can be solved by various methods, but they share a similar solution
method, namely, iterative optimization.
Depending on applications, the computation generated from AD can be quite
complex. They often form a directed acyclic graph, which can be referred to as
a computation graph. Based on the computation graph, we can perform various
optimizations to improve the execution speed, reduce memory usage, etc. A
computation graph plays a critical role in our system, and we introduce it in Chapter 6.

5
Chapter 1 Introduction

Finally, neural networks, as complex as their architectures can be, are in essence
also an extension of regression and therefore are also trained by iterative optimization.
We cover this topic in Chapter 5. With the popularity of machine learning and neural
networks, this series of advanced analytics, especially the core technique AD, has
become increasingly essential in modern numerical analysis library stacks. In this book,
we will briefly introduce these topics and their architecture in design in Owl.

Hardware and Deployment


In the next part, we discuss the execution backends Owl executes on in Chapter 7. The
first important backend we consider is hardware accelerators such as GPUs. Scientific
computing often involves intensive computations, and a GPU is important to accelerate
these computations by performing parallel computation on its massive cores. Besides,
there are growingly more types of hardware accelerators. For example, Google develops
the Tensor Processing Unit (TPU), specifically for neural network machine learning. It
is highly optimized for large batches in using TensorFlow. To improve performance of a
numerical library such as Owl, it is necessary to support multiple hardware platforms.
One idea is to “freeride” existing libraries that already support various hardware
platforms. We believe that a computation graph is a suitable intermediate representation
(IR) to achieve interoperability between different libraries. Along this line, we develop a
prototype symbolic layer system by using which the users can define a computation in
Owl and then turn it into an ONNX structure, which can be executed on many different
platforms such as TensorFlow. By using the symbolic layer, we show the system workflow
and how powerful features of Owl, such as algorithmic differentiation, can be used in
TensorFlow.
Besides aiming for maximal performance on accelerators, sometimes a numerical
library also targets to run in a wide range of environments, for example, to execute on
web browsers based on JavaScript for ease of access to many end users. Besides, with the
trending of edge computing and the Internet of Things, it is also crucial for numerical
libraries to support running on computation resource–limited devices. One approach is
to construct unikernel, a specialized minimal virtual machine image that only contains
necessary libraries and modules to support an application. In this book, we also
introduce Owl’s support for execution in this environment.

6
Chapter 1 Introduction

Research on Owl
In the last part of this book, we introduce two components in Owl: Zoo, for service
composition and deployment, and Actor, for distributed computing. The focus of these
two chapters is to present two pieces of research based on Owl.
In Chapter 9, we introduce the Zoo subsystem. It was originally developed to share
OCaml scripts. It is known that we can use OCaml as a scripting language as Python
(at certain performance cost because the code is compiled into bytecode). Even
though compiling into native code for production use is recommended, scripting is
still useful and convenient, especially for light deployment and fast prototyping. In
fact, the performance penalty in most Owl scripts is almost unnoticeable because the
heaviest numerical computation part is still offloaded to Owl which runs native code.
While designing Owl, our goal is always to make the whole ecosystem open, flexible,
and extensible. Programmers can make their own “small” scripts and share them with
others conveniently, so they do not have to wait for such functions to be implemented
in Owl’s master branch or submit something “heavy” to OPAM. Based on these
basic functionalities, we extend the Zoo system to address the computation service
composition and deployment issues.
Next, we discuss the topic of distributed computing. The design of distributed
and parallel computing module essentially differentiates Owl from other mainstream
numerical libraries. For most libraries, the capability of distributed and parallel
computing is often implemented as a third-party library, and the users have to deal with
low-level message passing interfaces. However, Owl achieves such capability through
its Actor subsystem. Distributed computing includes techniques that combine multiple
machines through a network, sharing data and coordinating progresses. With the fast-­
growing number of data and processing power they require, distributed computing
has been playing a significant role in current smart applications in various fields. Its
application is extremely prevalent in various fields, such as providing large computing
power jointly, fault-tolerant databases, file system, web services, and managing large-­
scale networks, etc.
In Chapter 10, we give a brief bird’s-eye view of this topic. Specifically, we introduce
an OCaml-based distributed computing engine, Actor. It has implemented three
mainstream programming paradigms: parameter server, map-reduce, and peer-to-peer.
Orthogonal to these paradigms, Actor also implements all four types of synchronization

7
Chapter 1 Introduction

barriers. We introduce four different types of synchronization methods or “barriers”


that are commonly used in current systems. We further elaborate how these barriers
are designed and provide illustrations from the theoretical perspective. Finally, we use
evaluations to show the performance trade-offs in using different barriers.

1.3 Summary
In this chapter, we introduced the theme of this book, which centers on the design of
Owl, a numerical library we have been developing. We briefly discussed why we build
Owl based on the OCaml language. And then we set a road map for the whole book,
which can be categorized into four parts: basic building block, advanced analytics,
execution in various environments, and research topics based on Owl. We hope you will
enjoy the journey ahead!

Open Access This chapter is licensed under the terms of the Creative
Commons Attribution 4.0 International License (http://creativecommons.
org/licenses/by/4.0/), which permits use, sharing, adaptation, distribution and
reproduction in any medium or format, as long as you give appropriate credit to the
original author(s) and the source, provide a link to the Creative Commons license and
indicate if changes were made.
The images or other third party material in this chapter are included in the chapter’s
Creative Commons license, unless indicated otherwise in a credit line to the material. If
material is not included in the chapter’s Creative Commons license and your intended
use is not permitted by statutory regulation or exceeds the permitted use, you will need
to obtain permission directly from the copyright holder.
8
Another random document with
no related content on Scribd:
V
ON THE ADVANTAGE OF HAVING A PATTERN
V
ON THE ADVANTAGE OF HAVING A PATTERN

No passage of Stevenson’s has been oftener quoted than his


confession how he taught himself the art of letters by playing “the
sedulous ape to many masters”; and in this avowal he had been
preceded by masters of style as dissimilar in their accomplishment
as Franklin and Newman. Stevenson may be overstating the case—
he had caught the trick of over-statement from Thoreau—but he is
not misstating it when he asserts that this is the only way to learn to
write. Certainly it is an excellent way, if we judge by its results in his
own case, in Franklin’s and in Newman’s. The method of imitative
emulation will help any apprentice of the craft to choose his words, to
arrange them in sentences and to build them up in coherent
paragraphs. It is a specific against that easy writing which is “cursed
hard reading.” But it goes no deeper than the skin, since it affords
insufficient support when the novice has to consider his structure as
a whole, the total form he will bestow upon his essay, his story, his
play.
In the choice of the proper framework for his conception the
author’s task is made measurably lighter if he can find a fit pattern
ready to his hand. Whether he shall happen upon this when he
needs it is a matter of chance, since it depends on what the
engineers call “the state of the art.” There have been story-tellers
and playwrights not a few who have gone astray and dissipated their
energies, not through any fault of their own, but solely because no
predecessor had devised a pattern suitable for their immediate
purpose. They have wandered afield because the trail had not been
blazed by earlier, and possibly less gifted, wayfarers and
adventurers.
Perhaps I can make clear what I mean by a concrete example not
taken from the art of letters. In Professor John C. Van Dyke’s acute
analysis of the traditions of American painting, he has told us that
when La Farge designed the ‘Ascension’ for the church of that name
in New York,

The architectural place for it was simplified by placing on the chancel wall of the
church a heavily gilded moulding, deep-niched, and with an arched top, which
acted at once both as a frame and a limit to the picture. The space was practically
that of a huge window with a square base and a half-top requiring for its filling two
groups of figures one above the other. La Farge placed his standing figures of the
apostles and the holy women in the lower space and their perpendicular lines
paralleled the uprights of the frame; at the top he placed an oval of angels about
the risen Christ, and again the rounded lines of the angel group repeated the
curves of the gilded arch.

Then Professor Van Dyke appends this significant comment:

There was no great novelty in this arrangement. It was frankly adopted from
Italian Renascence painting and had been used for high altar-pieces by all the
later painters—Andrea del Sarto, Raphael, Titian, Palma. They had worked out the
best way of filling that up-right-and-arched space, and La Farge followed the
tradition because he recognized its sufficiency.

In other words, the art of painting had so far advanced that La


Farge was supplied with the pattern best suited to his purpose; and
this pattern once accepted, he was at liberty to paint the picture as
he saw it, without wasting time in quest of another construction. The
picture he put within that frame was his and his only, even if the
pattern of it had been devised centuries before he was born. In thus
utilizing a framework invented by his predecessors he was not
cramped and confined; rather was he set free. So it is that to Milton
and to Wordsworth the rigidity of the sonnet was not a hindrance but
a help—especially to Wordsworth since it curbed his tendency to
diffuseness. Wordsworth himself declared his delight in the
restrictions of the sonnet:
In truth the prison into which we doom
Ourselves no prison is: and hence for me,
In sundry moods, ’twas pastime to be bound
Within the Sonnet’s scanty plot of ground;
Pleased if some Souls (for such there needs must be),
Who have felt the weight of too much liberty,
Should find brief solace here, as I have found.
That utterance of Wordsworth’s may be recommended to the
ardent advocates of Free Verse,—that is, of the verse which boasts
itself to be patternless and to come into being in response solely to
the whim of the moment. Sooner or later the Free Versifiers will
discover the inexorable truth in Huxley’s saying that it is when a man
can do as he pleases that his trouble begins.
Since I have ventured these three quotations I am emboldened to
make a fourth—from John Morley’s essay on Macaulay. After
informing us about the rules which Comte imposed on himself in
composition, Morley tells us that Comte

justified his literary solicitude by insisting on the wholesomeness alike to heart and
intelligence of submission to artificial restrictions. He felt, after he had once
mastered the habit of the new yoke, that it became the source of continual and
unforeseeable improvement even in thought, and he perceived that the reason
why verse is a higher kind of literary perfection than prose, is that verse imposes a
greater number of rigorous forms.

It is because of their rigorous forms that the ballade and the


rondeau have established themselves by the side of the sonnet; and
the lyrist who has learnt to love them finds in their fixity no curb on
his power of self-expression. So in the kindred art of music, the
sonata and the symphony are forms each with a law of its own; yet
the composer has abundant liberty within the law. He has all the
freedom that is good for him; and the prison to which he dooms
himself no prison is.

II

There is however a difference between a fixed form, such as the


sonata has and the sonnet, and the more flexible formula, such as
the arrangement within a framework which La Farge borrowed from
the painters of the Italian Renascence. A pattern of this latter sort is
less rigid; in fact, it is easily varied as successive artists modify it to
suit themselves.
Consider the eighteenth century essay which Steele devised with
the aid of hints he found in the ‘Epistles’ and even in the ‘Satires’ of
Horace, and which was enriched and amplified by Addison. The
pattern of the ‘Tatler’ and the ‘Spectator’ was taken over by a
heterogeny of other essayists in the course of four-score years,
notably by Johnson in the ‘Idler’ and the ‘Rambler’; and assuredly
Johnson if left to himself could never have invented a formula so
simple, so unpretending and so graceful. It was only a little departed
from by Goldsmith, and only a little more by Irving in the ‘Sketch-
Book,’ which is not so much a periodical (altho it was originally
published in parts) as it is a portfolio of essays and of essay-like
tales. From Irving, Thackeray borrowed more than the title of his
‘Paris Sketch-Book’ and ‘Irish Sketch-Book.’
Consider the earlier and in some measure stricter form of the
essay as it had been developed by Montaigne,—the pattern that
Montaigne worked out as he put more and more of himself into the
successive editions of his essays. He had begun intending little more
than a commonplace-book of anecdotes and quotations; and yet by
incessant interpolation and elaboration his book became at last the
intimate revelation of his own pungent individuality. This is the
pattern that Bacon adopted and adapted to his purpose, less
discursive and more monitory, but not less pregnant nor less
significant. And it is Montaigne’s formula, not greatly transformed by
Bacon, which Emerson found ready to his hand when he made his
essays out of his lectures, scattering his pearls of wisdom with a
lavish hand and not pausing to string them into a necklace. We
cannot doubt that the pattern of Montaigne and Bacon and Emerson
owed something also to their memory of Epictetus and Marcus
Aurelius.
Shakspere was as fortunate as Bacon in the fact that he had not to
waste time in vainly seeking new forms. He did not invent the sonnet
and he did not invent the sonnet-sequence; but he made his profit
out of them. Neither the stanza nor the structure of his two narrative
poems, ‘Venus and Adonis’ and the ‘Rape of Lucrece,’ was of his
contriving; he found them already in use and he did not go in search
of any overt novelty of form.
Scott, “beaten out of poetry by Byron,” as he himself phrased it,
turned to prose-fiction; and almost by accident he created the pattern
of the historical novel, with its romantic heroes and heroines and with
its realistic humbler characters. His earliest heroes and heroines in
prose were very like his still earlier heroes and heroines in verse;
and his realistic characters were the result of his expressed desire to
do for the Scottish peasant what Miss Edgeworth had done for the
Irish peasant. The first eight of the Waverley novels dealt only with
Scottish scenes; then in ‘Ivanhoe,’ and a little later in ‘Quentin
Durward,’ Scott enlarged his formula for the presentation of an
English and a French theme.
Since Scott’s day his pattern has approved itself to three
generations of novelists; and it is not yet outworn. In France Victor
Hugo and Alexander Dumas accepted it, each of them altering it at
will, feeling free to adjust it to their own differing necessities. In Italy it
was employed by Manzoni, in Poland by Sinckiewitz; and in
Germany by a horde of uninspired story-tellers. In the United States
it was at once borrowed by Cooper for the ‘Spy,’ the first American
historical novel. Then Cooper, having proved its value, took the
pattern which Scott had created for the telling of a story the action of
which took place on land, and in the ‘Pilot’ made it serve for a story
the action of which took place mainly on the sea,—perhaps a more
striking originality than his contemporaneous employment of it for a
series of tales the action of which took place in the forest.
It is one of the most fortunate coincidences in the history of
literature that Scott crossed the border and made a foray into English
history at the very moment when Cooper was ready to write fiction
about his own country; and it was almost equally unfortunate that
Charles Brockden Brown was born too early to be able to avail
himself of the pattern Scott and Cooper were to handle triumphantly.
Brown died a score of years before the publication of ‘Ivanhoe.’ He
left half-a-dozen novels of varying value, known only to devoted
students of American fiction. He had great gifts; he had invention
and imagination; he was a keen observer of human nature; he had a
rich faculty of description. (In one of his books there is a portrayal of
an epidemic of yellow fever in Philadelphia which almost challenges
comparison with De Foe’s ‘Journal of the Plague Year’.) But “the
state of the art” of fiction supplied Brown with no model appropriate
to his endowment; and therefore he had to do the best he could with
the unworthy pattern of the Gothic Romance of Horace Walpole and
Mrs. Radcliffe and of their belated followers, “Monk” Lewis and
Godwin. If Brown had been a contemporary of Cooper, then the
author of the ‘Last of the Mohicans’ might have had a worthy rival in
his own country.
The state of the art in his own time was a detriment to a far greater
story-teller than Brown or Cooper or Scott, to one of the greatest of
all story-tellers, to Cervantes. ‘Don Quixote’ abides as the
imperishable monument to his genius, to his wisdom, to his insight,
to his humor, to his all-embracing sympathy. None the less is it
sprawling in its construction and careless in its composition. There
were only two models available for Cervantes when he wrote this
masterpiece of fiction, the Romance of Chivalry and its antithesis,
the Romance of Roguery—the picaresque tale. The Romance of
Chivalry was generally chaotic and involute, with a plot at once
complicated and repetitious. The Romance of Roguery, born of an
inevitable reaction against the highflown and toplofty unreality of the
interminable narratives of knight-errantry, was quite as straggling in
its episodes; and it was also addicted to cruel and brutal practical
joking. For Cervantes these were unworthy patterns; and he had no
other. So it is that the method of ‘Don Quixote’ is sometimes
unsatisfactory, even when the manner is always beyond all cavil.
Moreover, it is evident that Cervantes builded better than he knew;
he seems not to have suspected the transcendent quality of his own
work; and therefore he did not take his task as seriously as he might.
As it has been well said, Cervantes came too early to profit by
Cervantes.
How much luckier are the novelists and short-story writers of to-
day! The state of the art has advanced to a point unforeseen even a
century ago. Whatever theme a writer of fiction may want to treat
now, he is never at a loss for a pattern, which will preserve him from
the misadventure which befell Cervantes. In its methods, if in nothing
else, fiction is a finer art than it was once upon a time. Consider
Rudyard Kipling, for example, who is almost infinitely various, and
who is always inexpugnably original. Whatever his subject might be,
there was always an appropriate pattern at his service; he had only
to pick and choose that which best suited his immediate need.
Consider Stevenson, again, and how he was able to play the
sedulous ape at one time to Scott and Dumas, and at another to
Hawthorne and Poe.

III

It is perhaps in the field of playmaking that the utility of the pattern


is most obvious. Sophocles modeled himself on Aeschylus, and then
modified the formula in his own favor. Calderon took over the pattern
that Lope de Vega had developed and the younger playwright
departed from it only infrequently. Racine modeled himself upon
Corneille; and then transformed the formula he borrowed in
obedience to his own genius. Victor Hugo took the theatrically
effective (but psychologically empty) pattern of contemporary
Parisian melodrama and draped its bare bones with his glittering
lyrism. Maeterlinck took the traditional formula of the fairy-play, the
féerie, and endowed it with the poetic feeling which delights us in the
‘Blue Bird.’ Oscar Wilde took the framework of Scribe and Sardou;
and he was thus enabled adroitly to complicate the situations of
‘Lady Windermere’s Fan.’
Then there is Ibsen, whose skilful construction has demanded the
praise of all students of the art and mystery of playmaking. He
started where Scribe and Sardou left off. The earliest of his social
dramas, the ‘League of Youth,’ is in accord with the pattern of Augier
and the younger Dumas. The next, the ‘Doll’s House,’ might have
been composed by Sardou—up to the moment in the final act when
husband and wife sit down on opposite sides of the table to talk out
their future relation. Thereafter Ibsen evolved from this French
pattern a pattern of his own which was exactly suited to his later
social dramas and which has in its turn been helpful to the more
serious dramatists of to-day.
As Shakspere had been content to take the verse-forms of his
predecessors and contemporaries, so he never hesitated to employ
their playmaking formulas. Kyd had developed the type of play which
we call the tragedy-of-blood; and Shakspere borrowed it for his ‘Titus
Andronicus’ (if this is his, which is more than doubtful) and even for
his ‘Hamlet,’ wherein it is purged of most of its violence. Marlowe
lifted into literature the unliterary and loosely knit chronicle-play; and
Shakspere enlarged this formula in ‘Richard III’ and ‘Richard II.’ It
was in his youth that Shakspere trod in the trail of Kyd and Marlowe;
and in his maturity he followed in the footsteps of his younger
friends, Beaumont and Fletcher, taking the pattern of their dramatic-
romance for his ‘Winter’s Tale’ and ‘Cymbeline.’ Due perhaps to the
fact that the state of the art did not provide him with a pattern for
what has been called high-comedy, Shakspere did not attempt any
searching study of Elizabethan society,—altho, of course, this may
have been because Elizabethan society was lacking in the delicate
refinements of fashion which are the fit background of high-comedy.
Whatever the explanation may be, it was left for Molière, inspired
by the external elegancies of the court of Louis XIV, to create the
pattern of high-comedy in ‘Tartuffe’ and the ‘Misanthrope’ and the
‘Femmes Savantes,’—the pattern which was to serve Congreve for
the ‘Way of the World,’ Sheridan for the ‘School for Scandal,’ Augier
and Sandeau for the ‘Gendre de Monsieur Poirier.’ And Molière
really created the formula, with little or no help from any earlier
dramatists, either Greek or Latin. Neither in Athens nor in Rome was
there the atmosphere of breeding which might have stimulated
Menander or Terence to the composition of comedies of this
distinction. It is the more remarkable that Molière should have
accomplished this feat, since he sought no originality of form in his
earlier efforts, contenting himself with the loose and liberal
framework of the Italian improvized plays, the Comedy-of-Masks.
One of the many reasons for the sterility of the English drama in
the middle of the nineteenth century is that the dramatists of our
language seem to have believed it their duty to abide by the patterns
which had been acceptable to the Jacobean and Restoration
audiences and which were not appropriate to the theater of the
nineteenth century, widely different in its size and in its scenic
appliances. The English poets apparently despised the stage of their
own time; and they made no effort to master its methods. As a result
they wrote dramatic poems and not poetic dramas. They did not
follow the example of Victor Hugo and lift into literature a type of play
which was unliterary. Stevenson, in his unfortunate adventures into
playmaking, made the unpardonable mistake of trying to varnish with
style a dramatic formula which had long ceased to be popular.
In the past half-century the men of letters of our language have
seen a great light. They have no contempt for the dramatic patterns
of approved popularity; and of these there are now a great many,
suitable for every purpose and adjustable to every need. They have
found out how to be theatrically effective without ceasing to be
literary in the best sense of the word,—that is to say, they are not
relying on “fine writing” but on clear thinking and on the honest
presentation of human nature, as they severally see it.
(1921)
VI
DID SHAKSPERE WRITE PLAYS TO FIT HIS ACTORS?
VI
DID SHAKSPERE WRITE PLAYS TO FIT HIS
ACTORS?

In his consideration of the organization of the Elizabethan dramatic


companies Professor Alwin Thaler pointed out that the company of
the Globe Theater in London, to which Shakspere belonged,
continued to contain the same actors year after year, the secessions
and the accessions being few and far between; and he explained
that this was “because its members were bound to one another by
ties of devoted personal friendship.” He noted that he had
“emphasized the influence exerted upon Shakspere the playwright
by his intimate knowledge of the men for whom his work was written,
and there can be no doubt that in working out some of his greatest
characters he must have remembered that Burbage was to act
them.” Then Professor Thaler filed a caveat, so to speak.

But the Shakspere muse was not of that sorry sort which produces made-to-
order garments to fit the tastes and idiosyncrasies of a single star. Far from being
one-man plays, the dramas were written for a great company of actors.... And
Richard Burbage, I imagine, would have had little inclination to surrender his place
among his peers for the artificial and idolatrous solitude of modern starhood.

In this last sentence Mr. Thaler confuses the issue. The question is
not whether Burbage wanted to go starring, supported by a more or
less incompetent company, but whether Shakspere did on occasion
choose to write a play which is in fact a made-to-order garment to fit
the idiosyncrasies of a single star. And when it is put in this way the
question is easy to answer. We know that Burbage played Richard
III, and if there ever was a star-part, if there ever was a one-man
play, if there ever was a piece cut and stitched to the measure of the
man who first performed it, then it is Richard III. Here we have a
dominating character to whom the other characters are sacrificed; he
is etched with bold strokes, whereas most of the others are only
faintly outlined. So long as Richard is powerfully seized and
rendered, then the rest of the acting is relatively unimportant.
Richard is the whole show. And while there is only a single star-part
in Richard III—Eclipse first and the rest nowhere—there are twin
star-parts in Macbeth, who are vigorously drawn, while the remaining
characters are merely brushed in, as Professor Bradley has noted.
Now, if this proves that Shakspere’s muse was of a sorry sort, then
that heavenly visitor is in no worse case than the muse of many
another dramatist. Sophocles is reported to have devised his great
tragic parts specially for one actor, whose name has not come down
to us. Racine wrote ‘Phèdre’ and ‘Andromaque,’ his masterpieces,
for Mlle. de Champsmeslé. Rostand wrote ‘Cyrano de Bergerac’ and
‘Chantecler’ for Coquelin. Sardou wrote ‘Fédora’ and ‘Théodora’ for
Sarah Bernhardt. The younger Dumas wrote the ‘Visite de Noces’ for
Desclée. Giacommetti wrote ‘Maria Antoinette’ for Ristori and the
‘Morte Civile’ for Salvini. D’Annunzio wrote the ‘Gioconda’ and the
‘Citta Morte’ for Duse. Bulwer-Lytton wrote the ‘Lady of Lyons’ and
‘Richelieu’ for Macready. Gilbert wrote ‘Comedy and Tragedy’ for
Mary Anderson. Legouvé has told us in detail the circumstances
which led to his writing (in collaboration with Scribe) ‘Adrienne
Lecouvreur’ for Rachel. Jules Lemaître has told us how and why he
came to compose his ‘Age Difficile’ for Coquelin; and Augustus
Thomas has told us how he came to compose his ‘In Mizzoura’ for
Goodwin. The line stretches out to the crack of doom. When
Shakspere chose to produce made-to-order garments to fit the
idiosyncrasies of a single actor, he was in very good company,
ancient and modern. And we may go further and assert that very few
of these plays are any the worse because they were made-to-order.
The great dramatists, whose works we analyze reverently in the
study, were all of them, in their own time, successful playwrights,
stimulated now and again by association with the most gifted and the
most accomplished of contemporary actors. If they had not made
their profit out of the histrionic ability of the foremost performers of
their own time and country, they would have been neglecting golden
opportunities.
Those who best know the conditions of playwriting will be the least
likely to deny that not a few of the great characters in the drama
came into being originally as parts for great actors. Of course, these
characters are more than parts; they transcend the endowment of
any one performer; they have complexity and variety; they are vital
and accusable human beings; but they were parts first of all more or
less made-to-order. In many cases we know the name of the actor
for whose performance the character was conceived, Burbage for
one, Mlle. de Champsmeslé for a second, Coquelin for a third. And
in many another case we lack definite knowledge and are left to
conjecture. There are peculiarities in the ‘Medea’ of Euripides, for
instance, which seem to me to point to the probability that it also was
a made-to-order garment.
To say that Sophocles and Euripides possibly did this cutting-to-fit,
that Shakspere and Racine and Rostand indisputably did it, is not to
imply that they did it always or even that they did it often. Perhaps
they did it more often than we shall ever know; perhaps they had
special actors in mind when they created characters which are not
star-parts. And this suggests a broadening of the inquiry.

II

After asserting that Shakspere’s were “far from being one-man


plays,” Professor Thaler reminded us that Shakspere’s dramas were
written “for a great company of actors”; and what is true of
Shakspere

holds good also of the Elizabethan drama in general. Its breadth and variety may
be ascribed in no slight degree to the fact that the organization of the dramatic
companies provided the great poets of a great age with ample facilities for the
interpretation of many characters and many phases of life.
This prompts a question as to whether Shakspere may not have
fitted other actors who were his associates at the Globe Theater
besides Burbage. That he did deliberately and repeatedly take the
measure of the foremost performer in the company and that his
dramatic genius was stimulated by the histrionic talent of Burbage, I
do not doubt. We cannot help seeing that Shakspere’s heroes
become older as Burbage himself advanced in years. Romeo being
intended for a fiery young fellow and Lear being composed for a
maturer man, who had become a more consummate artist. I have
suggested elsewhere the possibility—to my own mind a probability—
that Shakspere inserted the part of Jaques into ‘As You Like It’
specially for Burbage. Shakspere took his sequence of incidents
from Lodge’s ‘Rosalynd,’ in which there is no character which
resembles Jaques; and Jaques has nothing to do with the plot; he
remains totally outside the story; he exists for his own sake; and he
may very well have been thrust into ‘As You Like It’ because
Burbage was too important an actor to be left out of the cast and
because Orlando was not the kind of part in which Burbage at that
period of his artistic development would appear to best advantage.
If Shakspere made parts thus adjusted to the chief performer at
the Globe Theater, may he not also have proportioned other and less
important characters to the capabilities of one or another of the
actors whose histrionic endowment he was in the best possible
position to appreciate aptly, since he was acting every day by their
side? Is this something to which the greatest of dramatists would
scorn to descend? Has this ever been done by any other playwright
in all the long history of the stage?
When we turn the pages of that history in search of support for this
suggestion, we find it abundantly and super-abundantly. The
succession of comic operas which Gilbert devised to be set to music
by Sullivan reveal at once that they were contrived with reference to
the capacity and to the characteristics of the chief members of the
company at the Savoy Theater. The sequence of broadly humorous
pieces, farces which almost rose to be comedies and comedies
which almost relaxed into farces, written by Labiche, and by Meilhac
and Halévy for the Palais Royal theater were all of them so put
together as to provide appropriate parts for the quartet of comedians
who made that little house the home of perennial laughter in the third
quarter of the nineteenth century.
At the same time Meilhac and Halévy were contriving for the
Variétés the librettos of ‘Barbe-Bleue’ and the ‘Grande Duchesse de
Gérolstein,’ ‘Belle Hélène’ and ‘La Périchole,’ a series of opera-
bouffes enhanced by the scintillating rhythms of Offenbach and
adroitly adapted to the special talents of Schneider, of Dupuis and of
several of the other more or less permanent members of the
company. Almost simultaneously Augier and the younger Dumas
were giving to the Comédie-Française their social dramas, always
carefully made-to-order to suit the half-dozen leading members of
the brilliant company Perrin was then guiding. The ‘Fourchambault’
of Augier and the ‘Étrangère’ of Dumas are masterpieces of this
profitable utilization of the pronounced personalities of the
performers. The ‘Étrangère,’ in particular, would have been a very
different play if it had not contained characters made-to-order for
Sarah Bernhardt and Croizette, Got and Coquelin.
A little earlier the series of blank verse plays written by Gilbert for
the Haymarket Theater, of which ‘Pygmalion and Galatea’ won the
most protracted popularity, had their leading characters plainly
made-to-order for Mr. and Mrs. Kendal and for Buckstone himself.
And just as ‘Richard III’ and ‘King Lear’ are none the worse because
the central character was conceived also as an acting part for
Burbage, so Gilbert’s blank verse pieces, Augier’s social dramas,
Meilhac and Halévy’s farcical comedies lost nothing by their owing
some portion of their inspiration to the necessity of fitting the
accomplished comedians by whom the outstanding characters were
to be impersonated. I venture to express the opinion that this desire
to bring out the best the several actors had to give was helpful rather
than not, stimulatingly suggestive to the author when he was setting
his invention to work.
When we turn back the pages of stage-history from the nineteenth
century to the eighteenth we find perhaps the most striking of all
instances of made-to-order parts,—an instance which shows us not
one or two or three characters in a play, but almost every one of
them, composed and elaborated with an eye single to the original
performers. The ‘School for Scandal’ has been seen by hundreds
and read by thousands, who have enjoyed its effective situations, its
sparkling dialog and its contrasted characters, without any suspicion
that the persons of the play were made-to-order parts. Yet this
undisputed masterpiece of English comedy is what it is because its
clever author had succeeded to the management of Drury Lane,
where Garrick had gathered an incomparable company of
comedians; and in writing the ‘School for Scandal’ Sheridan peopled
his play with the characters which the members of this company
could personate most effectively.
King was Sir Peter, Mrs. Abington was Lady Teazle, Palmer was
Joseph Surface, Smith was Charles Surface; and they were so
perfectly fitted that they played with effortless ease. So closely did
Sheridan identify the parts with the performers that when a friend
asked him why he had written a five-act comedy ending in the
marriage of Charles and Maria without any love-scene for this
couple, he is reported to have responded: “But I couldn’t do it. Smith
can’t make love—and nobody would want to make love to Priscilla
Hopkins!”

III

It may be objected that Sheridan and Augier and Dumas were


after all dextrous playwrights and that they are no one of them to be
ranked with the truly great dramatists. While they might very well be
willing once in a way to turn themselves into dramaturgic tailors, this
is a servile complaisance of which the mighty masters of the drama
would never be guilty, from which indeed they would shrink with
abhorrence. But if we turn the pages of stage-history still further
back, from the eighteenth century to the seventeenth, we discover
that Molière did this very thing, the adjustment of a whole play to the
actors who were to perform it, not once as Sheridan did, but
repeatedly and regularly and in all his pieces, in his loftiest comedies
no less than his broadest and most boisterous farces. And there will
be found few competent critics to deny that Molière is one of the
supreme leaders of the drama, with an indisputable right to a place
by the side of Sophocles and Shakspere, even if he does not climb
to the austere and lofty heights of tragedy.
The more we know about the art of the theater and the more we
study the plays of Molière the more clearly do we perceive that he
was compelled to do persistently what Sheridan did only once. The
company at the Palais Royal was loyal to Molière; nearly all its
leading members came to Paris with him and remained with him until
his death fifteen years later. This company was strictly limited in
number; and as it had a permanent repertory and stood ready to
appear in any of its more successful plays at a moment’s notice,
outside actors could not be engaged for any special part,—even if
there had then been in Paris any available performers at liberty.
Molière could not have more parts in any of his pieces than there
were members of the company; and he could not put into any of his
pieces any character for which there was not a competent performer
in the company. No doubt, he must at times have felt this to be a
grievous limitation. That he never deals with maternal love may be
accounted for by the fact that he had no woman to play agreeable
“old women,”—the disagreeable elderly females being still played by
men, in accord with the medieval tradition. We know the name of the
male actor who appeared as Madame Pernelle in ‘Tartuffe,’ as the
wife in the ‘Bourgeois Gentilhomme’ and as the Comtesse
d’Escarbagnas.
Molière wrote many parts for his own acting; and as he was
troubled with a frequent cough, he sometimes makes coughing a
characteristic of the person he was to act. His brother-in-law, Béjart,
was lame; and so Molière describes a character written for this actor
as having a limp. His sister-in-law, Madeleine Béjart, was an actress
of authority; and so the serving maids he wrote for her are
domineering and provocative. But when she died and her place was
taken by a younger actress with an infectious laugh, the serving
maids in all the plays that Molière wrote thereafter are not
authoritative, and they are given occasion for repeated cachinnation.
And as this recruit, Mlle. Beauval, had a clever little daughter,
Molière did not hesitate to compose a part for a child in his ‘Malade
Imaginaire.’ When we have familiarized ourselves with the record of
the leading man, La Grange, of Madeleine Béjart, of Catherine de
Brie, and of Armande Béjart (Molière’s wife), we find it difficult to
study the swift succession of comedies without constantly feeling the
presence of the actors inside the characters written for them. We
recognize that it was not a matter of choice this fitting of the parts to
the performers; it was a matter of necessity; and even if it may have
irked him at times, Molière made the best of it and probably found
his profit in it.
Now Shakspere was subject to the same limitations as Molière. He
composed all his plays for one company, the membership of which
was fairly constant during a score of years and more. It was also a
repertory company with frequent changes of bill. It could never be
strengthened by the special engagement of an unattached
performer; it had to suffice, such as it was. So far as we can judge by
the scant external evidence and by the abundant internal evidence of
the plays written for them by Shakspere, Ben Jonson, Beaumont and
Fletcher, and the rest, the company was composed of unusually
competent performers. It is unthinkable that Shakspere should have
plotted his superb series of tragedies, making more and more
exacting demands on the impersonators of his tragic heroes, unless
he had a confident assurance that Burbage would be equal to them.
And this confidence could not fail to be a stimulus to him,
encouraging him to seek out stories for the ample display of his
friend’s great gifts.
From all we have learnt of late about Shakspere we are justified in
believing that he was a shrewd man of affairs with a keen eye to the
main chance. He was a sharer in the takings at the door; and he
could not but know that those plays are most attractive to the public
which contain the most parts demanding and rewarding good acting.
So we must infer that he put into his plays the characters in which he
judged that his comrades could appear to best advantage. He not
only wrote good parts for good actors, he wrote special parts for
special actors, shaping his characters to the performers who were to
impersonate them. In other words he provided, and he had to
provide, made-to-order garments.
That he did this repeatedly and regularly, just as Molière was to do
it three-quarters of a century later on the other side of the channel, is
plainly evident, altho we do not now know the special qualifications
of his actors as well as we do those of Molière’s. But we cannot
doubt that the company contained one actor of villains, of “heavies”
as they are termed in the theater. I hazard a guess that this was
Condell, afterwards the associate of Heming in getting out the First
Folio; but whoever he was, Condell or another, he was entrusted
with Iago, with Edmund in ‘King Lear,’ with the King in ‘Hamlet,’ and
with the rest of Shakspere’s bold, bad men.
We know that there were two low comedians in the company, who
appeared as the two Dromios, as the two Gobbos, as Launce and
Speed; and we know also that one of these was Will Kempe and that
when he left the Globe Theater his place was taken by Arnim. Now,
we can see that the Dromios, the Gobbos, Launce and Speed are
merely “clowns” as the Elizabethans called the funny men,—“Let not
your clowns speak more than is set down for them.” The Dromios
and the Gobbos and the corresponding parts in Shakspere’s earlier
plays, including Peter in ‘Romeo and Juliet,’ are only funny men, with
little individuality, almost characterless; and we may surmise that this
was due to Shakspere’s own inexperience in the delineation of
humorous character. But we may, if we choose, credit it also to the
fact that Kempe was only a funny man, and not a character-actor.
And we can find support for this in the superior richness and stricter
veracity of the low comedy characters composed by Shakspere after
Arnim took Kempe’s place,—Dogberry, the porter in ‘Macbeth,’ the
gravedigger in ‘Hamlet,’ comic parts which are also characters,
equipt with more or less philosophy. And again this may be ascribed
either to Shakspere’s own ripening as a humorist or to the richer
capacity of Arnim. But why may not these two causes have
coöperated?
Then there is the brilliant series of parts composed for a dashing
young comedian,—Mercutio, Gratiano, Cassio, Laertes. That these
successive characters were all entrusted to the same performer
seems to me beyond question; and it seems to me equally
indisputable that Shakspere knew what he was doing when he

You might also like