Source: rdd/FloatRDD.js

  1. /*
  2. * Copyright 2016 IBM Corp.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. module.exports = function(kernelP, server) {
  17. return (function() {
  18. var Utils = require('../utils.js');
  19. var gKernelP = kernelP;
  20. /*
  21. This is the wrapper class for org.apache.spark.api.java.JavaDoubleRDD
  22. a Java type Double = JavaScript type float thus the name change from
  23. DoubleRDD to FloatRDD
  24. */
  25. /**
  26. * @classdesc
  27. * @param {module:eclairjs/rdd.RDD} srdd
  28. * @class
  29. * @memberof module:eclairjs/rdd
  30. * @extends RDD
  31. */
  32. function FloatRDD() {
  33. Utils.handleConstructor(this, arguments, gKernelP);
  34. }
  35. /**
  36. * @param {module:eclairjs/rdd.RDD} rdd
  37. * @returns {module:eclairjs/rdd.FloatRDD}
  38. */
  39. FloatRDD.prototype.wrapRDD = function (rdd) {
  40. throw "not implemented by ElairJS";
  41. };
  42. /**
  43. * @returns {module:eclairjs/rdd.FloatRDD}
  44. */
  45. FloatRDD.prototype.cache = function () {
  46. throw "not implemented by ElairJS";
  47. };
  48. /**
  49. * Set this RDD's storage level to persist its values across operations after the first time
  50. * it is computed. Can only be called once on each RDD.
  51. * @param {module:eclairjs/storage.StorageLevel} newLevel
  52. * @returns {module:eclairjs/rdd.FloatRDD}
  53. */
  54. FloatRDD.prototype.persist = function (newLevel) {
  55. throw "not implemented by ElairJS";
  56. };
  57. /**
  58. * Mark the RDD as non-persistent, and remove all blocks for it from memory and disk.
  59. *
  60. * @param {boolean} [blocking] Whether to block until all blocks are deleted.
  61. * @returns {module:eclairjs/rdd.FloatRDD}
  62. */
  63. FloatRDD.prototype.unpersist = function (blocking) {
  64. throw "not implemented by ElairJS";
  65. };
  66. /**
  67. * @returns {float}
  68. */
  69. FloatRDD.prototype.first = function () {
  70. throw "not implemented by ElairJS";
  71. };
  72. /**
  73. * Return a new RDD containing the distinct elements in this RDD.
  74. * @param {number} [numPartitions]
  75. * @returns {module:eclairjs/rdd.FloatRDD}
  76. */
  77. FloatRDD.prototype.distinct = function (numPartitions) {
  78. throw "not implemented by ElairJS";
  79. };
  80. /**
  81. * Return a new RDD containing only the elements that satisfy a predicate.
  82. * @param {function} func
  83. * @returns {module:eclairjs/rdd.FloatRDD}
  84. */
  85. FloatRDD.prototype.filter = function (func, bindArgs) {
  86. throw "not implemented by ElairJS";
  87. };
  88. /**
  89. * Return a new RDD that is reduced into `numPartitions` partitions.
  90. * @param {number} numPartitions
  91. * @param {boolean} [shuffle]
  92. * @returns {module:eclairjs/rdd.FloatRDD}
  93. */
  94. FloatRDD.prototype.coalesce = function (numPartitions, shuffle) {
  95. throw "not implemented by ElairJS";
  96. };
  97. /**
  98. * Return a new RDD that has exactly numPartitions partitions.
  99. *
  100. * Can increase or decrease the level of parallelism in this RDD. Internally, this uses
  101. * a shuffle to redistribute data.
  102. *
  103. * If you are decreasing the number of partitions in this RDD, consider using `coalesce`,
  104. * which can avoid performing a shuffle.
  105. * @param {number} numPartitions
  106. * @returns {module:eclairjs/rdd.FloatRDD}
  107. */
  108. FloatRDD.prototype.repartition = function (numPartitions) {
  109. throw "not implemented by ElairJS";
  110. };
  111. /**
  112. * Return an RDD with the elements from `this` that are not in `other`.
  113. *
  114. * Uses `this` partitioner/partition size, because even if `other` is huge, the resulting
  115. * RDD will be <= us.
  116. * @param {module:eclairjs/rdd.FloatRDD} other
  117. * @returns {module:eclairjs/rdd.FloatRDD}
  118. */
  119. FloatRDD.prototype.subtract0 = function (other) {
  120. throw "not implemented by ElairJS";
  121. };
  122. /**
  123. * Return an RDD with the elements from `this` that are not in `other`.
  124. * @param {module:eclairjs/rdd.FloatRDD} other
  125. * @param {number} numPartitions
  126. * @returns {module:eclairjs/rdd.FloatRDD}
  127. */
  128. FloatRDD.prototype.subtract1 = function (other, numPartitions) {
  129. throw "not implemented by ElairJS";
  130. };
  131. /**
  132. * Return an RDD with the elements from `this` that are not in `other`.
  133. * @param {module:eclairjs/rdd.FloatRDD} other
  134. * @param {Partitioner} p
  135. * @returns {module:eclairjs/rdd.FloatRDD}
  136. */
  137. FloatRDD.prototype.subtract2 = function (other, p) {
  138. throw "not implemented by ElairJS";
  139. };
  140. /**
  141. * Return a sampled subset of this RDD.
  142. * @param {boolean} withReplacement
  143. * @param {float} fraction
  144. * @param {number} [seed]
  145. * @returns {module:eclairjs/rdd.FloatRDD}
  146. */
  147. FloatRDD.prototype.sample = function (withReplacement, fraction, seed) {
  148. throw "not implemented by ElairJS";
  149. };
  150. /**
  151. * Return the union of this RDD and another one. Any identical elements will appear multiple
  152. * times (use `.distinct()` to eliminate them).
  153. * @param {module:eclairjs/rdd.FloatRDD} other
  154. * @returns {module:eclairjs/rdd.FloatRDD}
  155. */
  156. FloatRDD.prototype.union = function (other) {
  157. throw "not implemented by ElairJS";
  158. };
  159. /**
  160. * Return the intersection of this RDD and another one. The output will not contain any duplicate
  161. * elements, even if the input RDDs did.
  162. *
  163. * Note that this method performs a shuffle internally.
  164. * @param {module:eclairjs/rdd.FloatRDD} other
  165. * @returns {module:eclairjs/rdd.FloatRDD}
  166. */
  167. FloatRDD.prototype.intersection = function (other) {
  168. throw "not implemented by ElairJS";
  169. };
  170. /**
  171. * @returns {float}
  172. */
  173. FloatRDD.prototype.sum = function () {
  174. throw "not implemented by ElairJS";
  175. };
  176. /**
  177. * Returns the minimum element from this RDD as defined by
  178. * the default comparator natural order.
  179. * @returns {float} the minimum of the RDD
  180. */
  181. FloatRDD.prototype.min = function () {
  182. throw "not implemented by ElairJS";
  183. };
  184. /**
  185. * Returns the maximum element from this RDD as defined by
  186. * the default comparator natural order.
  187. * @returns {float} the maximum of the RDD
  188. */
  189. FloatRDD.prototype.max = function () {
  190. throw "not implemented by ElairJS";
  191. };
  192. /**
  193. * Return a {@link StatCounter} object that captures the mean, variance and
  194. * count of the RDD's elements in one operation.
  195. * @returns {StatCounter}
  196. */
  197. FloatRDD.prototype.stats = function () {
  198. throw "not implemented by ElairJS";
  199. };
  200. /**
  201. * @returns {float}
  202. */
  203. FloatRDD.prototype.mean = function () {
  204. var args = {
  205. target: this,
  206. method: 'mean',
  207. returnType: Number
  208. };
  209. return Utils.generate(args);
  210. };
  211. /**
  212. * @returns {float}
  213. */
  214. FloatRDD.prototype.variance = function () {
  215. throw "not implemented by ElairJS";
  216. };
  217. /**
  218. * @returns {float}
  219. */
  220. FloatRDD.prototype.stdev = function () {
  221. throw "not implemented by ElairJS";
  222. };
  223. /**
  224. * Compute the sample standard deviation of this RDD's elements (which corrects for bias in
  225. * estimating the standard deviation by dividing by N-1 instead of N).
  226. * @returns {float}
  227. */
  228. FloatRDD.prototype.sampleStdev = function () {
  229. throw "not implemented by ElairJS";
  230. };
  231. /**
  232. * Compute the sample variance of this RDD's elements (which corrects for bias in
  233. * estimating the standard variance by dividing by N-1 instead of N).
  234. * @returns {float}
  235. */
  236. FloatRDD.prototype.sampleVariance = function () {
  237. throw "not implemented by ElairJS";
  238. };
  239. /**
  240. * @param {number} timeout
  241. * @param {float} [confidence]
  242. * @returns {PartialResult}
  243. */
  244. FloatRDD.prototype.meanApprox = function (timeout, confidence) {
  245. throw "not implemented by ElairJS";
  246. };
  247. /**
  248. * Approximate operation to return the sum within a timeout.
  249. * @param {number} timeout
  250. * @param {float} [confidence]
  251. * @returns {PartialResult}
  252. */
  253. FloatRDD.prototype.sumApprox = function (timeout, confidence) {
  254. throw "not implemented by ElairJS";
  255. };
  256. /**
  257. * Compute a histogram of the data using bucketCount number of buckets evenly
  258. * spaced between the minimum and maximum of the RDD. For example if the min
  259. * value is 0 and the max is 100 and there are two buckets the resulting
  260. * buckets will be [0,50) [50,100]. bucketCount must be at least 1
  261. * If the RDD contains infinity, NaN throws an exception
  262. * If the elements in RDD do not vary (max == min) always returns a single bucket.
  263. * @param {number} bucketCount
  264. * @returns {Pair}
  265. */
  266. FloatRDD.prototype.histogram0 = function (bucketCount) {
  267. throw "not implemented by ElairJS";
  268. };
  269. /**
  270. * Compute a histogram using the provided buckets. The buckets are all open
  271. * to the left except for the last which is closed
  272. * e.g. for the array
  273. * [1,10,20,50] the buckets are [1,10) [10,20) [20,50]
  274. * e.g 1<=x<10 , 10<=x<20, 20<=x<50
  275. * And on the input of 1 and 50 we would have a histogram of 1,0,0
  276. *
  277. * Note: if your histogram is evenly spaced (e.g. [0, 10, 20, 30]) this can be switched
  278. * from an O(log n) insertion to O(1) per element. (where n = # buckets) if you set evenBuckets
  279. * to true.
  280. * buckets must be sorted and not contain any duplicates.
  281. * buckets array must be at least two elements
  282. * All NaN entries are treated the same. If you have a NaN bucket it must be
  283. * the maximum value of the last position and all NaN entries will be counted
  284. * in that bucket.
  285. * @param {number[]} buckets
  286. * @returns {number[]}
  287. */
  288. FloatRDD.prototype.histogram1 = function (buckets) {
  289. throw "not implemented by ElairJS";
  290. };
  291. /**
  292. * @param {float[]} buckets
  293. * @param {boolean} evenBuckets
  294. * @returns {number[]}
  295. */
  296. FloatRDD.prototype.histogram2 = function (buckets, evenBuckets) {
  297. throw "not implemented by ElairJS";
  298. };
  299. /**
  300. * Save this FloatRDD as a text file, using string representations of elements.
  301. * @param {string} path
  302. * @param {boolean} [overwrite] defaults to false, if true overwrites file if it exists
  303. * @returns {Promise.<void>}
  304. */
  305. FloatRDD.prototype.saveAsTextFile = function(path) {
  306. var args = {
  307. target: this,
  308. method: 'saveAsTextFile',
  309. args: Utils.wrapArguments(arguments)
  310. };
  311. return Utils.generate(args);
  312. };
  313. /**
  314. * Save this FloatRDD as a SequenceFile of serialized objects.
  315. * @param {string} path
  316. * @param {boolean} [overwrite] defaults to false, if true overwrites file if it exists
  317. * @returns {Promise.<void>}
  318. */
  319. FloatRDD.prototype.saveAsObjectFile = function(path) {
  320. var args = {
  321. target: this,
  322. method: 'saveAsObjectFile',
  323. args: Utils.wrapArguments(arguments)
  324. };
  325. return Utils.generate(args);
  326. };
  327. /**
  328. * @param {string} name
  329. * @returns {module:eclairjs/rdd.FloatRDD}
  330. */
  331. FloatRDD.prototype.setName = function (name) {
  332. throw "not implemented by ElairJS";
  333. };
  334. FloatRDD.prototype.toString = function() {
  335. var args = {
  336. target: this,
  337. method: 'toString',
  338. returnType: String
  339. };
  340. return Utils.generate(args);
  341. };
  342. //
  343. // static methods
  344. //
  345. /**
  346. * @param {module:eclairjs/rdd.RDD} rdd
  347. * @returns {module:eclairjs/rdd.FloatRDD}
  348. */
  349. FloatRDD.fromRDD = function(rdd) {
  350. var args = {
  351. target: FloatRDD,
  352. method: 'fromRDD',
  353. args: Utils.wrapArguments(arguments),
  354. returnType: FloatRDD,
  355. kernelP: rdd.kernelP,
  356. static: true
  357. };
  358. return Utils.generate(args);
  359. };
  360. /**
  361. * @param {module:eclairjs/rdd.FloatRDD} rdd
  362. * @returns {module:eclairjs/rdd.RDD}
  363. */
  364. FloatRDD.toRDD = function (rdd) {
  365. throw "not implemented by ElairJS";
  366. };
  367. FloatRDD.moduleLocation = '/FloatRDD';
  368. return FloatRDD;
  369. })();
  370. };