Questions tagged [scalar]

In computing and programming, a scalar variable or value refers to a single value, as opposed to data structures such as arrays or lists.

In computing and programming, a scalar variable refers to a single value, as opposed to data structures such as or s. A scalar can be of any type, including a complex type such as an object or string. Being scalar only means that it is manipulated as a single value.

As an example, the string type in C++ is considered to be a scalar as it is a primitive type containing a single value, although in the C language there is no such primitive type. Thus, the char array implementation of strings typically used would not be considered as a scalar.

See also:

532 questions
8
votes
3 answers

Getting Current Date Time for a Random Number Generator's Seed

Preferably as a long. All the example I can find are getting the date/time as a string and not any scalar value. :)
bobber205
  • 12,948
  • 27
  • 74
  • 100
8
votes
2 answers

How to convert surrogate pair to Unicode scalar in Swift

The following example is taken from the Strings and Characters documentation: The values 55357 (U+D83D in hex) and 56374 (U+DC36 in hex) are the surrogate pairs that form the Unicode scalar U+1F436, which is the DOG FACE character. Is there any way…
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
8
votes
4 answers

How should I use Perl's scalar range operator?

What is the scalar ".." operator typical usage? Is it only selecting blocks of text? Interesting example by myself: sub get_next { print scalar($$..!$$), "\n"; } get_next for 1 .. 5; # prints numbers from 1 to 5 get_next for 1 .. 5; # prints…
Eugene Yarmash
  • 142,882
  • 41
  • 325
  • 378
8
votes
5 answers

Alternative for define array php

I'm looking for an alternative for define('name', array) as using an array in define gives me this error: Constants may only evaluate to scalar values in ... The array I'm mentioning contains strings only.
Anoniem Anoniem
  • 1,915
  • 6
  • 18
  • 19
7
votes
3 answers

Perl: does reassigning a new value to a scalar overwrite its current contents in RAM?

I'm using Perl for a security-related task and am wondering when a statement such as: $test = "new value" is executed, is the old value that $test created overwritten in RAM? If not, is there a way to force that to happen?
LawrenceC
  • 423
  • 2
  • 13
7
votes
4 answers

Passing a scalar reference in Perl

I know that passing a scalar to a sub is actually passing the reference, but since I am new to perl I still did the following test: #!/usr/bin/perl $i = 2; subr(\$i); sub subr{ print $_[0]."\n"; print $$_[0]."\n"; } I thought the first line…
user685275
  • 2,097
  • 8
  • 26
  • 32
7
votes
2 answers

Detecting element types in a mixed array

Im working with some code that has a subroutine which includes an array reference as one of the parameters. The elements in this incoming array can be either small arrays or strings. I want to determine what type each element is in order to do…
BentChainRing
  • 382
  • 5
  • 14
7
votes
3 answers

PHP array_replace_recursive if scalar, array_merge_recursive if array

I have some default configurations, and some specific configurations which would be configurable. I need to merge the specific configurations into the default configurations. In the case that the specific config option does not exist, the default…
Gravy
  • 12,264
  • 26
  • 124
  • 193
7
votes
1 answer

OpenCV scalar datatype, when to use?

Here we can hava a look on OpenCV's basic structures. My question is what exactly the datatype "scalar" is and when do i use it. Here you can see its definition: template class CV_EXPORTS Scalar_ : public Vec<_Tp, 4> { public: //!…
Jürgen K.
  • 3,427
  • 9
  • 30
  • 66
7
votes
1 answer

Bitwise-AND Slower with SIMD than Scalar

I've been trying to improve the performance of large (multi-gigabyte) bitarray operations. I'm no SIMD expert, but it appears SIMD is, in all cases, slower than scalar operations. I've tried several optimizations, including loop unrolling, to no…
7
votes
4 answers

PHP: Dynamic Object Names

Possible Duplicate: Get PHP class property by string This is my original code: function generateQuery($type, $language, $options) { // Base type $query = $this->Queryparts->print['filter']; // Language modifiers // Additional…
Jonas Ballestad
  • 159
  • 1
  • 1
  • 6
6
votes
3 answers

Most efficient way to multiply a small matrix with a scalar in numpy

I have a program whose main performance bottleneck involves multiplying matrices which have one dimension of size 1 and another large dimension, e.g. 1000: large_dimension = 1000 a = np.random.random((1,)) b = np.random.random((1,…
Nur L
  • 791
  • 7
  • 15
6
votes
1 answer

GraphQL.js - timestamp scalar type?

I am building a GraphQL schema programmatically and in need of a Timestamp scalar type; a Unix Epoch timestamp scalar type: const TimelineType = new GraphQLObjectType({ name: 'TimelineType', fields: () => ({ date: { type: new…
u-ways
  • 6,136
  • 5
  • 31
  • 47
6
votes
2 answers

convert pandas dataframe value to scalar

How do I convert a pandas data frame with 1 row, 1 column into a scalar value? import pandas as pd data = {'col1': 1} df = pd.DataFrame(data=d)
runningbirds
  • 6,235
  • 13
  • 55
  • 94
6
votes
1 answer

PHP7: shouldn't a scalar return type declaration accept integer?

I'm implementing an Iterator interface and if I implement it returning scalar (following the reference http://php.net/manual/en/class.iterator.php), I got this error: TypeError: Return value of Collection::key() must be an instance of scalar,…
1 2
3
35 36